我正在尝试创建自己的扩展窗口类JFrame
。但是,我对fullScreenBtn
. 在编写ActionListener.actionPerformed
函数时,我无法使用this
它所指的关键字new ActionListener
。我如何引用的实例MyWindow
?
public class MyWindow extends JFrame {
private static GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
private static GraphicsDevice gDev = gEnv.getDefaultScreenDevice();
private static JPanel toolbar = new JPanel();
private static JButton fullScreenBtn = new JButton("Show Full Screen");
private static boolean isFullScreen = false;
public MyWindow() {
toolbar.setLayout(new FlowLayout());
this.getContentPane().add(toolbar, BorderLayout.PAGE_START);
fullScreenBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Toggle full screen window
this.setUndecorated(!isFullScreen);
this.setResizable(isFullScreen);
gDev.setFullScreenWindow(this);
isFullScreen = !isFullScreen;
if (isFullScreen) {
fullScreenBtn.setText("Show Windowed");
} else {
fullScreenBtn.setText("Show Full Screen");
}
}
});
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
this.dispose();
System.exit(0);
}
});
}
}