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, "你点击了取消按钮"); }
}
}