run*_*nit 1 java action jframe jbutton
我如何让我的程序工作,以便在单击按钮时将其删除?
这是代码:
//Mainmenu
JFrame frame1 = new JFrame();
Container pane = frame1.getContentPane();
JButton a = new JButton(new ImageIcon("path2img"));
BufferedImage a1 = ImageIO.read(new File("path2img"));
public Menu() throws IOException {
frame1.setSize(300, 450);
frame1.setLocationRelativeTo(null);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setResizable(false);
frame1.setVisible(true);
pane.add(a);
a.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent aa) {
pane.remove(a);
}
});
}
Run Code Online (Sandbox Code Playgroud)
谢谢
| 归档时间: |
|
| 查看次数: |
2108 次 |
| 最近记录: |