如果想写点击事件来实现关闭窗口,试试 System.exit(0)
import java.awt.*import java.awt.event.*
import javax.swing.*
public class Practise{
public static void main(String[] args) {
new MyFrame()
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
final JButton btnChangeImage=new JButton("改变图标")
btnChangeImage.setIcon(new ImageIcon(".\\images\\icon1.png"))
btnChangeImage.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
btnChangeImage.setIcon(new ImageIcon(".\\images\\icon2.png"))
}
})
this.getContentPane().add(btnChangeImage)
this.setSize(300,200)
this.setLayout(new FlowLayout())
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)//用户单击“关闭”按钮时关闭窗口
this.setVisible(true)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)