首先要有一个界面类
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class win extends WindowAdapter{
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
//System.out.println("Window closing"+e.toString());
System.out.println("关闭");
System.exit(0);
}
@Override
public void windowActivated(WindowEvent e) {
//每次获得焦点 就会触发
System.out.println("激活焦点");
//super.windowActivated(e);
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
System.out.println("打开");
//super.windowOpened(e);
}
}
在主类的main方法中调用界面类
Frame f = new Frame("界面测试");
f.setSize(500,400); //设置界面大小
f.setLocation(300,200); //设置初始位置
f.setLayout(new FlowLayout()); //置界面显控件显示模式
f.addWindowFocusListener(new win());//引入界面类
f.setVisible(true); //显示为真
关于按钮的植入
Button testBtn = new Button("测试按钮");
testBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("你点击了测试按钮");
String i = JOptionPane.showInputDialog("");
System.out.println("你输入了:"+i);
}
});
f.add(testBtn);
关于信息框
JOptionPane.showMessageDialog(null, "你在编辑框中输入了:"+editText);
编辑框
TextArea TextEdit = new TextArea("13333333333355555555");
f.add(TextEdit);