2011-02-14 3 views
1

UPD : Solved!netbeans에 matisse가있는 Java - WindowListener를 구현할 수 없습니다.

안녕하세요!

저는 netbeans 6.9.1 (나는 matisse를 사용합니다)에서 JAVA GUI 애플리케이션을 개발하기 시작했습니다. 그래서 내 프로그램에 windowListener를 구현하기로 결정했지만 문제가 발생했습니다. 메인 프레임에 액세스 할 수 없습니다!

그 문제를 해결하는 방법을 아는 사람이 있습니까?

UPD : 예외가 발생하지 않습니다. 액세스 권한을 얻지 못하기 때문에 기본 프레임에 리스너를 추가 할 수 없습니다!

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); 

누군가에게 유용 할 수 있다고 생각합니다.

+1

어떤 예외 나 에러가 발생합니까? –

+0

이 작업을 수행하는 방법에 대한 정보는 매우 유용 할 것입니다. – justkt

+0

무엇을 사용하고 있습니까? 평범한 스윙 JFrame? 스윙 응용 프로그램 프레임 워크? Netbeans 플랫폼? – Puce

답변

1

응용 프로그램 프레임 워크를위한 JavaDoc에서 봐 (찾기 어려운,하지만의 here) :

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

나는 그것을 해결했다. 당신의 도움에 감사드립니다! – ExiRe

관련 문제