有很多时候发现窗口不能关闭,其实很简单的,只要加上下面背景绿色部分加上
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
方法就可以了,在30行;不多说,代码如下:
package Button;
import java.awt.*; import java.awt.event.*; import javax.swing.JFrame;public class MyFrame extends JFrame{ Button myButton; TextArea myTextArea; int count;// Frame f;public static void main(String[] args) {MyFrame myF = new MyFrame(); myF.setSize(300,300); myF.setVisible(true); myF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public MyFrame(){ super("Inner Class Frame"); myButton = new Button("click me"); myTextArea = new TextArea(); add(myButton,BorderLayout.CENTER); add(myTextArea,BorderLayout.NORTH); ButtonListener bList = new ButtonListener(); myButton.addActionListener(bList); } class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e){ count++; myTextArea.setText("button clicked" + count + "times"); }// end of innerclass ButtonListener }
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!