📄 infojmenu.java
字号:
/**
*文件:InfoJMenu.java
*说明:菜单组件
**/
package com.javaseries.java.component;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class InfoJMenu implements ActionListener{
int width=450,height=400,x=120,y=150;
private InfoInsertJPanel insertJPanel = new InfoInsertJPanel();
private InfoDeleteJPanel deleteJPanel = new InfoDeleteJPanel();
private InfoUpdateJPanel updateJPanel = new InfoUpdateJPanel();
private InfoGridByQueryJPanel gridJPanel = new InfoGridByQueryJPanel();
private JFrame mainFrame=null;//声明框架
private JMenuBar myMenuBar=null;//声明菜单栏
private JMenu fileMenu=null;
private JMenuItem file_Connect,file_ToFile,file_FromFile,file_Exit;
private JMenu opMenu=null;
private JMenuItem op_Insert,op_Delete,op_Update;
private JMenu queryMenu=null;
private JMenuItem qurey_Grid,query_Card;
private JMenu helpMenu=null;
private JMenuItem help_About;
private InfoFromFileJPanel fromfileJPanel;
public InfoJMenu(JFrame mainFrame){
this.mainFrame=mainFrame;
init();
}
//初始化
private void init(){
//建立菜单栏
myMenuBar = new JMenuBar();
//把菜单挂到窗口上
mainFrame.setJMenuBar(myMenuBar);
//在菜单栏中增加菜单
AddMenu();
//刷新主框架
mainFrame.setVisible(true);
myMenuBar = new JMenuBar();
mainFrame.setJMenuBar(myMenuBar);
AddMenu();
AddListener();
mainFrame.setVisible(true);
}
//在菜单栏中增加菜单
private void AddMenu(){
fileMenu = new JMenu("文件");
myMenuBar.add(fileMenu);
fileMenu.add(file_Connect = new JMenuItem("连接"));
fileMenu.addSeparator();
fileMenu.add(file_FromFile=new JMenuItem("导入数据"));
fileMenu.add(file_ToFile=new JMenuItem("导出数据"));
fileMenu.addSeparator();
fileMenu.add(file_Exit=new JMenuItem("退出"));
//在菜单栏中增加"op"菜单
opMenu = new JMenu("通讯录操作");
myMenuBar.add(opMenu);
opMenu.add(op_Insert = new JMenuItem("添加记录"));
opMenu.add(op_Delete = new JMenuItem("删除记录"));
opMenu.add(op_Update = new JMenuItem("修改记录"));
//在菜单栏中增加"query"菜单
queryMenu=new JMenu("通讯录查询");
myMenuBar.add(queryMenu);
//增加菜单项
queryMenu.add(qurey_Grid=new JMenuItem("表格显示"));
// queryMenu.add(query_Card=new JMenuItem("卡片显示"));
helpMenu =new JMenu("帮助");
myMenuBar.add(helpMenu);
helpMenu.add(help_About=new JMenuItem("关于系统"));
}
//*******************//
private void AddListener(){
help_About.addActionListener(this);
file_Exit.addActionListener(this);
op_Insert.addActionListener(this);
op_Update.addActionListener(this);
op_Delete.addActionListener(this);
file_FromFile.addActionListener(this);
qurey_Grid.addActionListener(this);
}
//******************//
public void actionPerformed(ActionEvent e){
String Command=e.getActionCommand();
if(e.getSource() instanceof JMenuItem){
if (Command.equals("退出"))
System.exit(0);
}
if (Command.equals("关于系统")){
JOptionPane.showMessageDialog(mainFrame,"学生通讯录系统 版本 1.0 作者:田志强 马岩","关于系统",JOptionPane.INFORMATION_MESSAGE);
}
if (Command.equals("添加记录")){
JDialog dialog = new JDialog (mainFrame,true);
dialog.setSize(width,height);
dialog.setLocation(x,y);
dialog.setTitle("插入名片");
dialog.getContentPane().add(insertJPanel);
dialog.setVisible(true);
}
if (Command.equals("修改记录")){
JDialog dialog = new JDialog (mainFrame,true);
dialog.setSize(width,height);
dialog.setLocation(x,y);
dialog.setTitle("修改记录名片");
dialog.getContentPane().add(updateJPanel);
dialog.setVisible(true);
}
if (Command.equals("删除记录")){
JDialog dialog = new JDialog (mainFrame,true);
dialog.setSize(width,height);
dialog.setLocation(x,y);
dialog.setTitle("删除名片");
dialog.getContentPane().add(deleteJPanel);
dialog.setVisible(true);
}
if(Command.equals("表格显示")){
JDialog dialog = new JDialog (mainFrame,true);
dialog.setSize(width,height);
dialog.setLocation(x,y);
dialog.setTitle("通讯录查询-表格显示");
dialog.getContentPane().add(new InfoGridByQueryJPanel());
dialog.setVisible(true);
}
if(Command.equals("导入数据")){
fromfileJPanel = new InfoFromFileJPanel(mainFrame);
}
}
//*******************//
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -