我正在尝试学习观察者模式的实现。
EventEmitter / EventTarget / EventDispatcher是观察者模式的一种实现,但我想知道这三者之间的区别。
任何帮助,将不胜感激?
我正在制作鼠标点击事件,我试图连续几次将它发送到某个节点.为此,我使用相同的MouseEvent对象,由于某种原因,这种方法不起作用.然而,当我每次手动创建事件时,系统工作.有谁知道这种行为的原因是什么?我试图改变timeStamp,但问题仍然存在.我可以像之前提到的那样解决问题,但我对这个MouseEvent以及相应的调度和处理子系统如何工作感兴趣.我在MDC页面上找到的MouseEvent规范似乎缺少很多信息.
Tnx的帮助!
我正在开发一个swing应用程序,我在其中有一个Factory类,它提供了组件,同时考虑了Singleton.喜欢:
public final class ComponentFactory {
private static LibraryFrame libraryFrame;
private static LibraryTableScrollPane libraryTableScrollPane;
public static synchronized LibraryFrame getLibraryFrame() {
if (libraryFrame == null) {
libraryFrame = new LibraryFrame();
}
return libraryFrame;
}
public static synchronized LibraryTableScrollPane getLibraryTableScrollPane() {
if(libraryTableScrollPane == null) {
libraryTableScrollPane = new LibraryTableScrollPane(getLibraryTable());
}
return libraryTableScrollPane;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用这个组件:
add(ComponentFactory.getLibraryTableScrollPane())
Run Code Online (Sandbox Code Playgroud)
我还创建了一个ListenerFactory类,它提供了各种Swing/AWT监听器.
这种模式有什么缺陷吗?我可以使用具有两个同时可见的父组件的相同组件或侦听器吗?
提前致谢.
我有一个 SwingWorker 线程,它启动一个模式对话框(从侦听启动的 StateValue 的属性更改侦听器),并且 swing 工作线程继续执行其工作。但是,看起来 did 方法没有被调用,因为它是在 EDT 上调用的,但 swing 工作线程的模式对话框阻止了 EDT。因此,我无法从 EDT(或完成方法)关闭对话框。现在,我只是在该方法结束时从 doInBackground 关闭对话框,但这从 doInBackground 看来有点不安全,因为它不在 EDT 上。处理这个问题的最佳方法是什么?谢谢。
我想用JOptionPanes 处理一些例外.这是主要方法:
public class MainRun {
public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(new SubstanceRavenGraphiteGlassLookAndFeel());
}catch (Exception e){
e.printStackTrace();
}
new MainGui().setVisible(true);
new Initialized().start();
new PriorityMessageQueue().start();
}
});
Run Code Online (Sandbox Code Playgroud)
MainGui是JFrame应用程序的主窗口().我在PriorityMessageQueue线程中处理了异常.
public class PriorityMessageQueue extends Thread {
@Override
public void run() {
while (true) {
try {
instantMessages = instant.getMobitelMessagesToBeSent();
} catch (Exception ex) {
JOptionPane.showMessageDialog(
null,
ex.getMessage(),
"Database Error",
JOptionPane.ERROR_MESSAGE);
}
...
Run Code Online (Sandbox Code Playgroud)
在我运行之后,我收到了一个错误
org.jvnet.substance.api.UiThreadingViolationException: Component creation must …Run Code Online (Sandbox Code Playgroud) 我使用cocos2d-x 3.0 RC1,我有以下问题.据我所知,cocos2d-x有一个(集中式)事件调度程序,它实现为单例,以便我可以将事件从任何地方发送到任何地方.现在在最终版本中,它不是单身,我不能使用EventDispatcher::getInstance().为什么集中的EventDispatcher被认为是错误的?在这种情况下,我如何从一个不是a的类发送一个事件cocos2d::Node到另一个不是cocos2d::Node哪一个?
我有一个需要与事件一起传递的参数.在尝试通过扩展类将它放在类型上失败之后,我在另一个SO问题中被建议写一个自定义事件.
我之前尝试过这个但是我无法弄清楚如何发送它,因为我只想Event.COMPLETE在FileReference上发送带有普通事件的另一个参数.我不能Event.COMPLETE解雇然后发送我的事件,因为那时我将在同一条船上...所需的参数不会在初始Event.COMPLETE对象中,所以我将无法调度传递该参数的新事件实际执行工作的代码.
非常感谢所有帮助,非常需要它.谢谢.
基本上,我需要Event.COMPLETE完全按照原样替换功能,我只需要一个能够保存我额外属性的事件.请告诉我有一些方法可以做到这一点.
apache-flex events actionscript-3 event-dispatching custom-events
为什么当我单击Enter my application冻结时执行我的程序时?
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.io.*;
import java.net.*;
public class KnockKnockUI{
private Socket kkSocket = null;
private PrintWriter out = null;
private BufferedReader in = null;
JTextArea clientArea;
JTextArea serverArea;
public KnockKnockUI(){
establishConnection();
initComponents();
}
public void initComponents(){
JFrame frame = new JFrame("Chat");
frame.setVisible(true);
frame.setSize(320,189);
frame.getContentPane().setLayout(null);
serverArea = new JTextArea();
serverArea.setLineWrap(true);
serverArea.setBounds(10, 11, 284, 45);
frame.getContentPane().add(serverArea);
clientArea = new JTextArea();
clientArea.setBounds(10, 67, 284, 46);
frame.getContentPane().add(clientArea); …Run Code Online (Sandbox Code Playgroud) 我创建了一个带有组合框和一个按钮的JFrame,它将创建一个新线程并继续执行操作.我想要一个新的JFrame从每个新线程开始,将日志输出到新的JFrame.但即使我将与JFrame相关的代码放在新线程中并关闭该JFrame,它也会结束整个程序而不是运行的线程.制作我想要的最佳方法是什么?我只是希望在每个新线程启动时打开一个新的JFrame,当我关闭该JFrame时它将结束该线程.
问候!
我试图在框架中显示一个简单的jtable,但它没有显示表的列,我跟着oracle教程中的示例,但有一些我做得不对.该程序正在编译和运行.这是代码:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class SimpleTableDemo extends JPanel
{
SimpleTableDemo()
{
String[] columnNames = {"#",
"Repayment Dates",
"Principle Amount",
"Interest",
"Comission fee",
"Total installement amount",
"Principle balance"};
// BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN);
//each line of the two dimentional array is a line in the table
Object[][] data = {
{new Integer(1), new java.util.Date(), new BigDecimal(12509.23).setScale(2, RoundingMode.HALF_EVEN), new BigDecimal(1571.77).setScale(2, …Run Code Online (Sandbox Code Playgroud) 这是我有史以来第一次使用创建自定义事件调度程序和订阅者,所以我试图围绕它进行处理,但我似乎无法找出为什么我的自定义事件没有被调度。
我正在关注文档,就我而言,我需要在有人在网站上注册后立即发送事件。
所以在我的内部,我registerAction()正在尝试发送这样的事件
$dispatcher = new EventDispatcher();
$event = new RegistrationEvent($user);
$dispatcher->dispatch(RegistrationEvent::NAME, $event);
Run Code Online (Sandbox Code Playgroud)
这是我的RegistrationEvent课
namespace AppBundle\Event;
use AppBundle\Entity\User;
use Symfony\Component\EventDispatcher\Event;
class RegistrationEvent extends Event
{
const NAME = 'registration.complete';
protected $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function getUser(){
return $this->user;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的RegistrationSubscriber课
namespace AppBundle\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class RegistrationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array(
array('onKernelResponsePre', …Run Code Online (Sandbox Code Playgroud) 我有一个JDialg来显示某个任务的进度.要显示和隐藏对话框,我有以下方法,
public class ProgressDisplayer extends javax.swing.JDialog {
......
public void s_show() {
this.setTitle("Month End Status");
setModal(true);
setResizable(false);
pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public void s_hide() {
this.dispose();
}
...........
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从线程中关闭这个JDialog框时,虽然它显示正常但我在调用pd.s_hide()方法时无法隐藏它.
...........
public void run() {
ProgressDisplayer pd = new ProgressDisplayer();
pd.s_show();
Thread.sleep(1000);
pd.s_hide();
}
.............
Run Code Online (Sandbox Code Playgroud)
请帮助我
我有jtable的问题.
我有许多线程,每个线程都必须向jTable添加一行,但表格仍为空.我正在使用netbeans,图形完全独立于逻辑.有谁可以帮助我吗?
这是我用来添加行的代码
MainGui.java
public void addToTable(String from, String to, int request, int response, String timeElapsed) {
Object [][] temp = new Object [data.length + 1][5];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < 5; j++) {
temp[i][j] = data[i][j];
}
}
temp[data.length][0] = from;
temp[data.length][1] = to;
temp[data.length][2] = request;
temp[data.length][3] = response;
temp[data.length][4] = timeElapsed;
data = temp;
table.setModel(new DefaultTableModel(data, columnName));
}
Run Code Online (Sandbox Code Playgroud)
MyThread.java
public void run() {
try { …Run Code Online (Sandbox Code Playgroud) java ×8
swing ×7
concurrency ×3
jtable ×2
apache-flex ×1
c++ ×1
cocos2d-x ×1
eventemitter ×1
events ×1
javascript ×1
jdialog ×1
jframe ×1
joptionpane ×1
jscrollpane ×1
mouseevent ×1
php ×1
singleton ×1
substance ×1
swingworker ×1
symfony ×1