1
UPD:解決!Java在netbeans中使用matisse - 無法實現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);
我認爲這可能對某人有用。
你得到任何異常或任何錯誤? – 2011-02-14 14:15:29
有關您在何處/如何進行此操作的信息會非常有用。 – justkt 2011-02-14 14:16:02