【问题标题】:Java with matisse in netbeans - can't implement WindowListenerNetbeans中带有matisse的Java - 无法实现WindowListener
【发布时间】:2011-02-14 14:11:34
【问题描述】:

UPD:已解决!

美好的一天!

我开始在 netbeans 6.9.1 中开发 JAVA GUI 应用程序(我使用 matisse)。所以我决定在我的程序中实现 windowListener 但我遇到了问题。我无法访问主框架!

有人知道如何解决这个问题吗?

更新: 我没有遇到任何异常等。我无法为主机添加侦听器,因为我不知道如何获得访问权限!

这是生成代码的示例:

public class INotePadView extends FrameView 
{

  public INotePadView(SingleFrameApplication app)
  {
      super(app);

      initComponents(); //autogenerated method, nothing interesting.

      // status bar initialization - message timeout, idle icon and busy animation, etc
      ResourceMap resourceMap = getResourceMap();
      int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
      messageTimer = new Timer(messageTimeout, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              statusMessageLabel.setText("");
          }
      });

      messageTimer.setRepeats(false);
      int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
      for (int i = 0; i < busyIcons.length; i++) {
          busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
      }

      busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
              statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
          }
      });

      idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
      statusAnimationLabel.setIcon(idleIcon);
      progressBar.setVisible(false);

      // connecting action tasks to status bar via TaskMonitor
      TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
      taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
          public void propertyChange(java.beans.PropertyChangeEvent evt) {
              String propertyName = evt.getPropertyName();
              if ("started".equals(propertyName)) {
                  if (!busyIconTimer.isRunning()) {
                      statusAnimationLabel.setIcon(busyIcons[0]);
                      busyIconIndex = 0;
                      busyIconTimer.start();
                  }
                  progressBar.setVisible(true);
                  progressBar.setIndeterminate(true);
              } else if ("done".equals(propertyName)) {
                  busyIconTimer.stop();
                  statusAnimationLabel.setIcon(idleIcon);
                  progressBar.setVisible(false);
                  progressBar.setValue(0);
              } else if ("message".equals(propertyName)) {
                  String text = (String)(evt.getNewValue());
                  statusMessageLabel.setText((text == null) ? "" : text);
                  messageTimer.restart();
              } else if ("progress".equals(propertyName)) {
                  int value = (Integer)(evt.getNewValue());
                  progressBar.setVisible(true);
                  progressBar.setIndeterminate(false);
                  progressBar.setValue(value);
              }
          }
      });

  }

  @Action
  public void showAboutBox() {
      if (aboutBox == null) {
          JFrame mainFrame = INotePadApp.getApplication().getMainFrame();
          aboutBox = new INotePadAboutBox(mainFrame);
          aboutBox.setLocationRelativeTo(mainFrame);
      }
      INotePadApp.getApplication().show(aboutBox);
  }

//Other generated code

回答: 我找到了解决这个问题的方法。

WindowListener winListener = new TestWindowListener();
    JFrame mainFrame = super.getFrame();
    mainFrame.addWindowListener(winListener);

我认为它可能对某人有用。

【问题讨论】:

  • 您是否遇到任何异常或错误?
  • 有关您在哪里/如何执行此操作的一些信息将非常有帮助。
  • 你在用什么?普通的 Swing JFrame? Swing 应用程序框架? Netbeans 平台?
  • 据我了解这个问题:matisse 不提供对“主框架”的访问,所以他不知道如何在那里添加一个监听器(仅使用 matisse)。
  • Andreas_D 你是对的!我使用 matisse 创建按钮等。

标签: java swing matisse windowlistener


【解决方案1】:

查看应用程序框架的 Javadoc(很难找到,但它是 here):

WindowListener winListener = new TestWindowListener();
JFrame mainFrame = app.getMainFrame();
mainFrame.addWindowListener(winListener);

【讨论】:

    猜你喜欢
    • 2014-03-13
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    相关资源
    最近更新 更多