?? 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 {
// 定義數(shù)據(jù)庫變量
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;
// 定義數(shù)據(jù)表顯示項
//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;
// 構(gòu)造函數(shù)
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,"是否真的退出貨物管理系統(tǒng)","提示",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ))
{
Con.closeConn();
dispose();
System.exit(0);
}
} catch (Exception q) {
}
}});
}
// 菜單實現(xiàn)函數(shù)
private void jbMenuInit() {
this.setTitle("貨物管理系統(tǒng)");
this.setSize(new Dimension(1024,756));
titleLabel=new JLabel(new ImageIcon (".\\hf.jpg"));
setJMenuBar(mbar);
// 實現(xiàn)文件菜單
mbar.add(fileMenu);
fileMenu.setMnemonic('F');
fileMenu.setText("管理員登錄");
//實現(xiàn)管理員登錄子菜單
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();
}
});
// 實現(xiàn)退出子菜單
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) {
}
}
});
// 實現(xiàn)貨物信息菜單
mbar.add(goodMenu);
goodMenu.setMnemonic('g');
goodMenu.setText("貨物信息");
// 實現(xiàn)庫存貨物瀏覽子菜單
JMenuItem goodscanItem = new JMenuItem("庫存貨物瀏覽");
goodMenu.add(goodscanItem);
goodscanItem.setEnabled(true);
goodscanItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Goodscanform listScan = new Goodscanform();
}
});
//實現(xiàn)庫存貨物添加
goodMenu.add(goodaddItem);
goodaddItem.setEnabled(false);
goodaddItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GoodAddForm listAdd= new GoodAddForm();
}
});
//實現(xiàn)庫存貨物修改
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);
}
}
}
});
//實現(xiàn)出貨入貨管理子菜單
goodMenu.add(ioItem);
ioItem.setEnabled(false);
ioItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Ioform manageForm = new Ioform();
}
});
// 實現(xiàn)雇員管理菜單
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();
}
});
// 實現(xiàn)幫助菜單
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) {
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -