进货系统应用程序设计部分.docx
《进货系统应用程序设计部分.docx》由会员分享,可在线阅读,更多相关《进货系统应用程序设计部分.docx(35页珍藏版)》请在冰豆网上搜索。
进货系统应用程序设计部分
应用程序设计部分
环境:
eclipse7.0
连接:
JDBC连接SQLserver2000
登陆窗体代码Login.java
packageFram.login;
importjava.awt.Color;
importjava.awt.EventQueue;
importjava.awt.Font;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjava.sql.Connection;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importjavax.swing.JButton;
importjavax.swing.JDialog;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPasswordField;
importjavax.swing.JTextField;
importChaXun.lianjie;
publicclassLoginextendsJDialog{
privateJPasswordFieldpasswordField;
privateJTextFieldtextField_user;
privateJTextFieldtextField;
staticLogindialog;
publicstaticvoidmain(Stringargs[]){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
dialog=newLogin();
dialog.addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
dialog.setVisible(true);
}catch(Exceptione){
e.printStackTrace();}}});}
/**
*Createthedialog
*/
publicLogin(){
super();
setTitle("登陆系统");
getContentPane().setLayout(null);
setBounds(100,100,435,281);
finalJLabellabel=newJLabel();
label.setForeground(Color.RED);
label.setFont(newFont("",Font.PLAIN,26));
label.setBackground(Color.CYAN);
label.setText("登录进货管理系统");
label.setBounds(66,0,257,100);
getContentPane().add(label);
textField=newJTextField();
textField.setBackground(Color.BLUE);
textField.setBounds(0,0,437,100);
getContentPane().add(textField);
finalJLabellabel_1=newJLabel();
label_1.setText("用户名");
label_1.setBounds(98,119,48,18);
getContentPane().add(label_1);
textField_user=newJTextField();
textField_user.setBounds(166,117,87,22);
getContentPane().add(textField_user);
passwordField=newJPasswordField();
passwordField.setBounds(166,145,87,22);
getContentPane().add(passwordField);
finalJLabellabel_1_1=newJLabel();
label_1_1.setText("密码");
label_1_1.setBounds(98,147,48,18);
getContentPane().add(label_1_1);
finalJButtonbutton=newJButton();
button.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
Connectionconn=lianjie.getConnection();
try{
Statements=conn.createStatement();
Stringsql="select*fromuser_ID";
ResultSetrs=s.executeQuery(sql);//执行sql语句
String[]name=newString[rs.getMetaData().getColumnCount()];
while(rs.next())
{
name[0]=rs.getString("username").toString();
name[1]=rs.getString("password").toString();
}
System.out.println(textField_user.getText().toString().equals(name[0]));
if(!
textField_user.getText().equals(name[0].toString()))
{
JOptionPane.showMessageDialog(null,"用户名错误");
return;
}
elseif(!
passwordField.getText().equals(name[1]))
{
JOptionPane.showMessageDialog(null,"密码错误");
return;
}
else
{
JHFramd=newJHFram();
d.setVisible(true);
dialog.setVisible(false);
}
rs.close();
s.close();
conn.close();
}catch(SQLExceptione){
e.printStackTrace();}
}
});
button.setText("登陆");
button.setBounds(166,184,60,22);
getContentPane().add(button);
finalJButtonbutton_1=newJButton();
button_1.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
System.exit(0);
}
});
button_1.setText("退出");
button_1.setBounds(240,184,60,22);
getContentPane().add(button_1);
Datedate=newDate();
SimpleDateFormatfrom=newSimpleDateFormat("yyyy-MM-dd");
Stringtimes=from.format(date);
finalJLabellabel_2=newJLabel();
label_2.setBackground(Color.CYAN);
label_2.setForeground(newColor(0,0,255));
label_2.setText("当前日期:
"+times);
label_2.setBounds(166,224,134,23);
getContentPane().add(label_2);
finalJLabellabel_2_1=newJLabel();
label_2_1.setForeground(newColor(0,0,255));
label_2_1.setText("制作人:
李芳、肖海叶");
label_2_1.setBounds(306,224,121,23);
getContentPane().add(label_2_1);
}
}
主窗体:
JHFram.java
packageFram.login;
importjava.awt.Color;
importjava.awt.Component;
importjava.awt.Container;
importjava.awt.EventQueue;
importjava.awt.Font;
importjava.awt.SystemColor;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjava.sql.Connection;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importjavax.swing.JButton;
importjavax.swing.JComboBox;
importjavax.swing.JComponent;
importjavax.swing.JDesktopPane;
importjavax.swing.JDialog;
importjavax.swing.JInternalFrame;
importjavax.swing.JLabel;
importjavax.swing.JLayeredPane;
importjavax.swing.JMenu;
importjavax.swing.JMenuBar;
importjavax.swing.JMenuItem;
importjavax.swing.JPanel;
importjavax.swing.JPopupMenu;
importjavax.swing.JProgressBar;
importjavax.swing.JScrollPane;
importjavax.swing.JTabbedPane;
importjavax.swing.JTable;
importjavax.swing.JTextField;
importjavax.swing.JToolBar;
importTianjia.TKuCunShangPin;
importChaXun.CJinHuoDan;
importChaXun.CJinHuoYuan;
importChaXun.CKuCunShangPin;
importChaXun.lianjie;
publicclassJHFramextendsJDialog{
privateJTextFieldtextField_1;
privateJTextFieldtextField;
/**
*Launchtheapplication
*@paramargs
*/
JHFramdialog;
publicstaticvoidmain(Stringargs[]){
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
try{
JHFramdialog=newJHFram();
dialog.addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
dialog.setVisible(true);
}catch(Exceptione){
e.printStackTrace();
}
}
});
}
/**
*Createthedialog
*/
publicJHFram(){
super();
setTitle("车站管理系统");
getContentPane().setLayout(null);
setBounds(100,100,500,362);
finalJMenuBarmenuBar=newJMenuBar();
menuBar.setBackground(Color.CYAN);
setJMenuBar(menuBar);
finalJMenumenu=newJMenu();
menu.setText("查询");
menuBar.add(menu);
finalJMenuItemnewItemMenuItem=newJMenuItem();
newItemMenuItem.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
CJinHuoDanji=newCJinHuoDan();
ji.setVisible(true);
}
});
newItemMenuItem.setText("进货单");
menu.add(newItemMenuItem);
finalJMenuItemnewItemMenuItem_2=newJMenuItem();
newItemMenuItem_2.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
CJinHuoYuanjing=newCJinHuoYuan();
jing.setVisible(true);
}
});
newItemMenuItem_2.setText("进货员");
menu.add(newItemMenuItem_2);
finalJMenuItemnewItemMenuItem_3=newJMenuItem();
newItemMenuItem_3.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
CKuCunShangPinck=newCKuCunShangPin();
ck.setVisible(true);
}
});
newItemMenuItem_3.setText("库存商品");
menu.add(newItemMenuItem_3);
finalJMenumenu_1=newJMenu();
menu_1.setText("添加数据");
menuBar.add(menu_1);
finalJMenuItemnewItemMenuItem_6=newJMenuItem();
newItemMenuItem_6.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEventarg0){
TKuCunShangPintij=newTKuCunShangPin();
tij.setVisible(true);
}
});
newItemMenuItem_6.setText("添加商品入库");
menu_1.add(newItemMenuItem_6);
finalJMenuItemnewItemMenuItem_1=newJMenuItem();
newItemMenuItem_1.addActionListener(newActionListener(){
publicvoidactionPerformed(finalActionEvente){
System.exit(0);
}
});
newItemMenuItem_1.setBackground(Color.CYAN);
newItemMenuItem_1.setText("退出");
menuBar.add(newItemMenuItem_1);
finalJLabellabel=newJLabel();
label.setForeground(newColor(255,0,0));
label.setFont(newFont("",Font.PLAIN,16));
Connectionconn=lianjie.getConnection();
Statements;
try{
s=conn.createStatement();
Stringsql="select*fromuser_ID";
ResultSetrs=s.executeQuery(sql);//执行sql语句
String[]name=newString[rs.getMetaData().getColumnCount()];
while(rs.next())
{
name[0]=rs.getString("username").toString();
name[1]=rs.getString("password").toString();
}
rs.close();
s.close();
conn.close();
Datedate=newDate();
SimpleDateFormatfrom=newSimpleDateFormat("yyyy-MM-dd");
Stringtimes=from.format(date);
label.setText("操作员:
"+name[0].toString()+"当前日期:
"+times);
}catch(SQLExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
label.setBounds(177,267,297,26);
getContentPane().add(label);
textField_1=newJTextField();
textField_1.setBackground(newColor(153,204,255));
textField_1.setBounds(0,0,492,261);
textField_1.setEditable(false);
getContentPane().add(textField_1);
//
}
/**
*WindowBuildergeneratedmethod.
*Pleasedon'tremovethismethodoritsinvocations.
*ItusedbyWindowBuildertoassociatethe{@linkjavax.swing.JPopupMenu}withparent.
*/
privatestaticvoidaddPopup(Componentcomponent,finalJPopupMenupopup){
component.addMouseListener(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
if(e.isPopupTrigger())
showMenu(e);
}
publicvoidmouseRel