0
下面的代碼顯示了Gui類的內部幀監聽器。內部框架偵聽器應該將save(JMenuItem)設置爲啓用或禁用,但它什麼也不做。我不知道問題出在哪裏。我嘗試了幾件事,但沒有任何作用。內部幀監聽器不工作
下面是代碼:
public class Gui implements InternalFrameListener, ActionListener{
MyInternalFrame frame;
JMenuItem save;
public Gui(JDesktopPane desktop, final JMenuItem save) {
// TODO Auto-generated constructor stub
frame = new MyInternalFrame(title, img);
this.save = save;
frame.setVisible(true);
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
frame.addInternalFrameListener(this);
// options(name, desktop);
}
class MyInternalFrame extends JInternalFrame {
static final int xPosition = 30, yPosition = 30;
public MyInternalFrame(String title, ImagePlus img) {
super(title, true,true, true, true);
setSize(img.getHeight(), img.getWidth());
// Set the window's location.
setLocation(xPosition * openFrameCount, yPosition * openFrameCount);
}
}
public void actionPerformed(ActionEvent e){
frame.addInternalFrameListener(this);
System.out.println("beingg called");
}
@Override
public void internalFrameActivated(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(true);
}
@Override
public void internalFrameClosed(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(false);
}
@Override
public void internalFrameClosing(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(false);
}
@Override
public void internalFrameDeactivated(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(false);
}
@Override
public void internalFrameDeiconified(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(true);
}
@Override
public void internalFrameIconified(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(false);
}
@Override
public void internalFrameOpened(InternalFrameEvent arg0) {
// TODO Auto-generated method stub
save.setEnabled(true);
}
}
這應該拋出一個NullPointerException,因爲從不分配保存。 – Soana
你的MyInternalFrame類在哪裏我沒有看到代碼中的任何地方????? –
如果可能,請發佈MyInternalFrame類的源代碼。另外super(imp)給出了編譯時錯誤,你還沒有定義什麼是imp? –