📄 mainframe.java
字号:
package good;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class Mainframe extends JFrame implements ActionListener {
// 定义数据库变量
DataConn Con = null;
// 定义菜单项
JMenuBar mbar = new JMenuBar();
JMenu fileMenu = new JMenu();
JMenu goodMenu = new JMenu();
JLabel titleLabel=new JLabel();
static JMenu employeeMenu = new JMenu();
//static JMenu ioMenu = new JMenu();
static JMenu clientMenu = new JMenu();
static JMenu imanufacturerMenu = new JMenu();
static JMenu aboutMenu = new JMenu();
static JMenuItem goodmodiItem = new JMenuItem("库存货物修改");
static JMenuItem goodaddItem = new JMenuItem("库存货物添加");
static JMenuItem goodsdeleItem = new JMenuItem("货物资料删除");
static JMenuItem ioItem = new JMenuItem("出货入货管理");
static Image bg = Toolkit.getDefaultToolkit().createImage( Mainframe.class.getResource("hf.jpg"));
//Good good=new Good();
//Good good=new Good();
static URL path=null;
// 定义数据表显示项
//final static JDesktopPane desktopPane = new JDesktopPane();
protected static boolean checkMenu;
protected static final String QUESTION_MESSAGE = null;
private static final Color RED = null;
Employee employee=new Employee();
Client client=new Client();
Imanufacturer imanufacturer=new Imanufacturer();
// JTable table;
// 构造函数
public Mainframe() {
Con = new DataConn();
jbMenuInit();
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e){
try {
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(Mainframe.this,"是否真的退出货物管理系统","提示",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ))
{
Con.closeConn();
dispose();
System.exit(0);
}
} catch (Exception q) {
}
}});
}
// 菜单实现函数
private void jbMenuInit() {
this.setTitle("货物管理系统");
this.setSize(new Dimension(1024,756));
titleLabel=new JLabel(new ImageIcon (".\\hf.jpg"));
setJMenuBar(mbar);
// 实现文件菜单
mbar.add(fileMenu);
fileMenu.setMnemonic('F');
fileMenu.setText("管理员登录");
//实现管理员登录子菜单
JMenuItem managerItem = new JMenuItem("管理员登录");
fileMenu.add(managerItem);
managerItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//GoodAddForm listAdd= new GoodAddForm()
Login login=new Login();
//setMemu();
}
});
// 实现退出子菜单
JMenuItem fileExitItem = new JMenuItem("退出");
fileMenu.add(fileExitItem);
fileExitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(Mainframe.this,"是否真的退出程序","提示",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ))
{
Con.closeConn();
dispose();
System.exit(0);
}
} catch (Exception q) {
}
}
});
// 实现货物信息菜单
mbar.add(goodMenu);
goodMenu.setMnemonic('g');
goodMenu.setText("货物信息");
// 实现库存货物浏览子菜单
JMenuItem goodscanItem = new JMenuItem("库存货物浏览");
goodMenu.add(goodscanItem);
goodscanItem.setEnabled(true);
goodscanItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Goodscanform listScan = new Goodscanform();
}
});
//实现库存货物添加
goodMenu.add(goodaddItem);
goodaddItem.setEnabled(false);
goodaddItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GoodAddForm listAdd= new GoodAddForm();
}
});
//实现库存货物修改
goodMenu.add(goodmodiItem);
goodmodiItem.setEnabled(false);
goodmodiItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GoodModiForm listModi= new GoodModiForm();
}
});
// 库存资料删除子菜单
goodMenu.add(goodsdeleItem);
goodsdeleItem.setEnabled(false);
goodsdeleItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String resultCode;
resultCode=JOptionPane.showInputDialog(Mainframe.this,"请输入要删除的货物编号:","删除提示",1);
if (resultCode.trim().length() >0 )
{
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(Mainframe.this,"确信删除货物编号为:"+resultCode,"提示",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ))
{
deleData("goods","goodId",resultCode,false);
JOptionPane.showConfirmDialog(Mainframe.this,"删除成功!","提示",2);
}
}
}
});
//实现出货入货管理子菜单
goodMenu.add(ioItem);
ioItem.setEnabled(false);
ioItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Ioform manageForm = new Ioform();
}
});
// 实现雇员管理菜单
mbar.add(employeeMenu);
employeeMenu.setMnemonic('C');
employeeMenu.setText("雇员管理");
employeeMenu.setEnabled( false);
//雇员资料添加子菜单
JMenuItem employeeaddItem = new JMenuItem("雇员资料添加");
employeeMenu.add(employeeaddItem);
employeeaddItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EmployeeAddform employeeAddform = new EmployeeAddform();
}
});
// 雇员资料子菜单
JMenuItem employeemodiItem = new JMenuItem("雇员资料修改");
employeeMenu.add(employeemodiItem);
employeemodiItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EmployeeModiform employeeModiform = new EmployeeModiform();
}
});
// 雇员资料删除子菜单
JMenuItem employeedeleItem = new JMenuItem("雇员资料删除");
employeeMenu.add(employeedeleItem);
employeedeleItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String resultCode;
resultCode=JOptionPane.showInputDialog(Mainframe.this,"请输入要删除的会员编号:","删除提示",1);
if (resultCode.trim().length() >0 )
{
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(Mainframe.this,"确信删除会员编号为:"+resultCode,"提示",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ))
{
deleData("employee","employeeid",resultCode,true);
JOptionPane.showConfirmDialog(Mainframe.this,"删除成功!","提示",2);
}
}
}
});
//客户管理
mbar.add(clientMenu);
clientMenu.setMnemonic('M');
clientMenu.setText("客户管理");
clientMenu.setEnabled( false);
//添加子菜单
JMenuItem addItem = new JMenuItem("客户资料添加");
clientMenu.add(addItem);
addItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ClientAddform lendForm = new ClientAddform();
}
});
//修改子菜单
JMenuItem modiItem = new JMenuItem("客户资料修改");
clientMenu.add(modiItem);
modiItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ClientModiform lendForm = new ClientModiform();
}
});
JMenuItem clientdeleItem = new JMenuItem("客户资料删除");
clientMenu.add(clientdeleItem);
clientdeleItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String resultCode;
resultCode=JOptionPane.showInputDialog(Mainframe.this,"请输入要删除的客户编号:","删除提示",1);
if (resultCode.trim().length() >0 )
{
if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(Mainframe.this,"确信删除客户编号为:"+resultCode,"提示",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE ))
{
deleData("client","clientName",resultCode,false);
JOptionPane.showConfirmDialog(Mainframe.this,"删除成功!","提示",2);
}
}
}
});
// 进货厂商管理
mbar.add(imanufacturerMenu);
imanufacturerMenu.setMnemonic('S');
imanufacturerMenu.setEnabled( false);
imanufacturerMenu.setText("进货厂商管理");
JMenuItem manufactureradd = new JMenuItem("进货厂商添加");
imanufacturerMenu.add(manufactureradd);
manufactureradd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImanufacturerAddForm ImanufacturerAddForm = new ImanufacturerAddForm();
}
});
// 实现帮助菜单
mbar.add(aboutMenu);
aboutMenu.setMnemonic('A');
aboutMenu.setText("帮助");
//JMenuItem helpItem = new JMenuItem("用户名及密码均为 1");
Container c=this.getContentPane();
JLabel img=new JLabel(new ImageIcon(bg));
c.add(img);
this.show();
}
public static void main(String[] args) {
Mainframe resumeTable = new Mainframe();
}
public void deleData(String talbe,String field,String fieldValue,boolean isInt)
{
DataConn storCon = new DataConn();
String delSql = null;
try{
if (isInt)
delSql="delete from "+talbe+" where "+field+"="+fieldValue;
else
delSql="delete from "+talbe+" where "+field+"='"+fieldValue+"'";
storCon.dataConnDerectForMySql();
storCon.executeDerectUpdate(delSql);
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public void setMemu()
{
employeeMenu.setEnabled( true);
clientMenu.setEnabled( true);
imanufacturerMenu.setEnabled( true);
goodmodiItem.setEnabled( true);
goodaddItem .setEnabled( true);
ioItem .setEnabled( true);
goodsdeleItem .setEnabled( true);
}
public void actionPerformed(ActionEvent actionEvent) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -