java中如何通过菜单选项打开一个页面然后关闭当前窗口,求大神!
packagetxl;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.uti...
package txl;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.List;
public class BjtxyShouYe extends JFrame{
private JLabel lbl;
private JMenu open;
private JMenuBar mb;
private JMenuItem search,edit,delete,look,exit;
public BjtxyShouYe(){
super("班级通讯录");
Container c = getContentPane();
mb = new JMenuBar();
open = new JMenu("操 作");
search = new JMenuItem("查询");
edit = new JMenuItem("修改");
delete = new JMenuItem("删除");
look = new JMenuItem("查看");
exit = new JMenuItem("退出");
open.addActionListener(new HandLer());
search.addActionListener(new HandLer());
edit.addActionListener(new HandLer());
delete.addActionListener(new HandLer());
look.addActionListener(new HandLer());
exit.addActionListener(new HandLer());
//添加菜单项
open.add(search);
open.add(edit);
open.add(delete);
open.add(look);
//在菜单中添加分隔条
open.addSeparator();
open.add(exit);
mb.add(open);
setJMenuBar(mb);//设置菜单栏
final JLabel label = new JLabel();
label.setBounds(0, 0, 0, 0);
label.setIcon(null); // 窗体背景
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //获取当前屏幕大小
this.setBounds((screenSize.width-400)/2,(screenSize.height-400)/2,400,400);
this.setVisible(true);
}
class HandLer implements ActionListener{
public void actionPerformed(ActionEvent e){
JMenuItem mi = (JMenuItem)e.getSource();
if(mi == search){
String searchName = new String();
searchName = JOptionPane.showInputDialog(null,"请输入姓名:","查询",JOptionPane.QUESTION_MESSAGE);
List listSearch = Dao.selectStudent(searchName);
//this.dispose();
}
if(mi == look){
new Look();
this.dispose();
}
if(mi == edit){
//this.dispose();
//new Edit();
}
if(mi == delete){
}
if(mi == exit){
System.exit(0);
}
}
}
public static void main(String[] args){
new BjtxyShouYe();
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.List;
public class BjtxyShouYe extends JFrame{
private JLabel lbl;
private JMenu open;
private JMenuBar mb;
private JMenuItem search,edit,delete,look,exit;
public BjtxyShouYe(){
super("班级通讯录");
Container c = getContentPane();
mb = new JMenuBar();
open = new JMenu("操 作");
search = new JMenuItem("查询");
edit = new JMenuItem("修改");
delete = new JMenuItem("删除");
look = new JMenuItem("查看");
exit = new JMenuItem("退出");
open.addActionListener(new HandLer());
search.addActionListener(new HandLer());
edit.addActionListener(new HandLer());
delete.addActionListener(new HandLer());
look.addActionListener(new HandLer());
exit.addActionListener(new HandLer());
//添加菜单项
open.add(search);
open.add(edit);
open.add(delete);
open.add(look);
//在菜单中添加分隔条
open.addSeparator();
open.add(exit);
mb.add(open);
setJMenuBar(mb);//设置菜单栏
final JLabel label = new JLabel();
label.setBounds(0, 0, 0, 0);
label.setIcon(null); // 窗体背景
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //获取当前屏幕大小
this.setBounds((screenSize.width-400)/2,(screenSize.height-400)/2,400,400);
this.setVisible(true);
}
class HandLer implements ActionListener{
public void actionPerformed(ActionEvent e){
JMenuItem mi = (JMenuItem)e.getSource();
if(mi == search){
String searchName = new String();
searchName = JOptionPane.showInputDialog(null,"请输入姓名:","查询",JOptionPane.QUESTION_MESSAGE);
List listSearch = Dao.selectStudent(searchName);
//this.dispose();
}
if(mi == look){
new Look();
this.dispose();
}
if(mi == edit){
//this.dispose();
//new Edit();
}
if(mi == delete){
}
if(mi == exit){
System.exit(0);
}
}
}
public static void main(String[] args){
new BjtxyShouYe();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询