import java.awt.event.*; //导入awt事件中所有的类
import java.awt.*; //导入窗体工具
import javax.swing.JFrame; //导入swing包中JFrame
import javax.swing.JOptionPane;//导入 swing中JOptionPane
public class myframe extends JFrame{ //传递参数构造窗体
public static void main(String[] args){
final Frame F=new Frame("佳木斯114网库欢迎您!");//设置窗体标题
F.setSize(800,600);
F.setLocation(300,400); //设置位置,大小,背景色,可见
F.setBackground(Color.red);
F.setVisible(true);
Button btn1=new Button("首页");
Button btn2=new Button("关于我们"); //设置5个按钮,并命名
Button btn3=new Button("招聘");
Button btn4=new Button("行业动态");
Button btn5=new Button("联系我们");
F.setLayout(new FlowLayout()); //设置按钮摆放方式
F.add(btn1,"North");
F.add(btn2,"South"); //按钮位置的摆放
F.add(btn3,"West");
F.add(btn4,"East");
F.add(btn5,"Center");
TextField tf=new TextField(80);//设置文本输入区
F.add(tf,"Left");
F.setVisible(true); //文本框可见
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){ //设置窗体按钮的监听器
JOptionPane.showMessageDialog(null,"欢迎光临,谢谢!");//设置对话框并为对话框设置内容
}
});
F.setVisible(true);
F.addWindowListener( new MyWindowListener()); //设置监听,关闭按钮响应事件
}
private static void setLayout(FlowLayout flowLayout) {
// TODO Auto-generated method stub
}
}
class MyWindowListener implements WindowListener{
public void windowOpened(WindowEvent e){
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowClosed(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}
求更好的改进方案!
------解决方案--------------------------------------------------------
LZ想改进什么啊?
------解决方案--------------------------------------------------------
LZ 发code用下脚本啊,这样看的多累