📄 loadpanel.java
字号:
package file2;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class loadPanel extends JPanel implements ActionListener {
//set用来存储登陆成功后的管理员名字和密码
private ResultSet set=null;
//引入数据库连接组件
private DBConnection con=null;
//声明是否是管理员
private boolean isAdministrator=false;
//声明标签
private JLabel notice1=null;
private JLabel notice2=null;
private JLabel name=null;
private JLabel password=null;
//声明文本框
private TextField nameTextField=null;
private TextField passwordTextField=null;
//声明"登陆"和"重置"按钮
private JButton load=null;
private JButton reset=null;
//声明存放各种控件的面版
private JPanel noticePanel=null;
private JPanel nameAndPasswordPanel=null;
private JPanel loadAndResetPanel=null;
public loadPanel(){
notice1=new JLabel("提示:只有本系统的管理员才能进行有关本系统的各种操作!");
notice2=new JLabel("如您是管理员请在下面输入您的名字和密码!");
name=new JLabel("名字:");
password=new JLabel("密码:");
nameTextField=new TextField(20);
passwordTextField=new TextField(20);
passwordTextField.setEchoChar('*');
load=new JButton("登陆");
reset=new JButton("重置");
noticePanel=new JPanel();
noticePanel.setLayout(new GridLayout(2,1));
noticePanel.add(notice1);
noticePanel.add(notice2);
nameAndPasswordPanel=new JPanel();
nameAndPasswordPanel.setLayout(new GridLayout(2,2));
nameAndPasswordPanel.add(name);
nameAndPasswordPanel.add(nameTextField);
nameAndPasswordPanel.add(password);
nameAndPasswordPanel.add(passwordTextField);
loadAndResetPanel=new JPanel();
loadAndResetPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
loadAndResetPanel.add(load);
loadAndResetPanel.add(reset);
this.setLayout(new GridLayout(3,1));
this.add(noticePanel);
this.add(nameAndPasswordPanel);
this.add(loadAndResetPanel);
load.addActionListener(this);
reset.addActionListener(this);
}
/*public ResultSet getSet(){
return set;
}*/
public void actionPerformed(ActionEvent e){
if(e.getSource()==load){
try{
String name=nameTextField.getText().trim();
String password=passwordTextField.getText().trim();
String sql="select* from administrator where administrator='"+name+"' and password='"+password+"'";
con=new DBConnection();
set=con.executeSelect1(sql);
if(set.next()){
isAdministrator=true;
JOptionPane.showMessageDialog(null, "登陆成功!","提示",JOptionPane.INFORMATION_MESSAGE);
String querySql="select* from Third_Catalog where store_in<=limit";
ResultSet rs=con.executeSelect1(querySql);
int count=0;
while(rs.next()){
count++;
}
//JOptionPane.showMessageDialog(null, count+"", "", JOptionPane.INFORMATION_MESSAGE);
String[][] data=new String[count][3];
count=0;
rs.beforeFirst();
while(rs.next()){
data[count][0]=rs.getString("Third_name");
data[count][1]=(new Integer(rs.getInt("store_in"))).toString();
data[count][2]=(new Integer(rs.getInt("limit"))).toString();
count++;
}
String[] title={"具体商品名称","库存量","最小库存量"};
if(count>0){
JTable table=new JTable(data,title);
JScrollPane tablePane=new JScrollPane(table);
JLabel notice=new JLabel("管理员注意了,以下商品的库存不足,请及时进货!");
JPanel noticePane=new JPanel();
noticePane.setBackground(Color.gray);
noticePane.add(notice,BorderLayout.NORTH);
JPanel echo=new JPanel();
echo.setLayout(new GridLayout(2,1));
echo.add(noticePane);
echo.add(tablePane);
/*JWindow window=new JWindow();
window.setBackground(Color.lightGray);*/
JDialog dialog=new JDialog(new JFrame(),true);
dialog.setSize(400, 250);
dialog.setLocation(100, 50);
dialog.getContentPane().add(echo);
dialog.setVisible(true);
/*window.add(noticePane,BorderLayout.NORTH);
window.add(tablePane, BorderLayout.CENTER);
window.setSize(400,300);
window.setLocation(800, 200);
window.setVisible(true);
window.toFront();
window.dispose();*/
}
return;
}else{
JOptionPane.showMessageDialog(null, "该管理员不存在!","警告",JOptionPane.ERROR_MESSAGE);
return;
}
}catch(Exception excep){
//sqle.printStackTrace();
JOptionPane.showMessageDialog(null, "请您检查数据库服务器是否处于打开状态.","警告",JOptionPane.ERROR_MESSAGE);
return;
}finally{
con.resetCon();
}
}
if(e.getSource()==reset){
nameTextField.setText("");
passwordTextField.setText("");
return;
}
}
public boolean getIsAdministrator(){
return this.isAdministrator;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -