Java编写一个简单的窗口程序,流程是什么?
1个回答
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test3 extends JFrame implements ActionListener{
JMenu m;
JMenuItem mi1,mi2;
JMenuBar mb;
public Test3(){
m = new JMenu("学生查询");
mi1 = new JMenuItem("确认");
mi2 = new JMenuItem("取消");
mb = new JMenuBar();
m.add(mi1);
m.add(mi2);
mb.add(m);
this.setJMenuBar(mb);
this.setSize(400,300);
this.setLocationRelativeTo(null);//窗口居中
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mi1.addActionListener(this);
mi2.addActionListener(this);
}
public static void main(String[] args){
new Test3();
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==mi1){
JOptionPane.showMessageDialog(null, "你点击了确定按钮"); }else{
JOptionPane.showMessageDialog(null, "你点击了取消按钮"); }
}
}
import java.awt.*;
import java.awt.event.*;
public class Test3 extends JFrame implements ActionListener{
JMenu m;
JMenuItem mi1,mi2;
JMenuBar mb;
public Test3(){
m = new JMenu("学生查询");
mi1 = new JMenuItem("确认");
mi2 = new JMenuItem("取消");
mb = new JMenuBar();
m.add(mi1);
m.add(mi2);
mb.add(m);
this.setJMenuBar(mb);
this.setSize(400,300);
this.setLocationRelativeTo(null);//窗口居中
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mi1.addActionListener(this);
mi2.addActionListener(this);
}
public static void main(String[] args){
new Test3();
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==mi1){
JOptionPane.showMessageDialog(null, "你点击了确定按钮"); }else{
JOptionPane.showMessageDialog(null, "你点击了取消按钮"); }
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询