📄 server.java
字号:
import java.net.*;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.*;
import javax.swing.*;
import server.Application_Server;
import server.Item_Server;
import server.Member_Server;
import server.ServerThread;
import server.Store_Server;
public class server extends JFrame implements WindowListener{
static final int port=8080;
ServerSocket ss;
JTextArea jtaControl=new JTextArea();
JTextField jtfID;
JPasswordField jpfPW;
JFrame frmAdimin;
Boolean isTrue;
server() throws IOException{
try {
ss=new ServerSocket(port);
ServerLogOn();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Server Started");
try{
while(true)
{
Socket s=ss.accept();
new ServerThread(s,jtaControl,s.getInetAddress().getHostAddress());
}
}catch(IOException e){
e.printStackTrace();
}
finally{
ss.close();
}
}
void ServerLogOn()
{
frmAdimin=new JFrame("管理员登录");
frmAdimin.setSize(400, 300);
JLabel labelID=new JLabel("系统帐号");
JLabel labelPW=new JLabel(" 密码");
jtfID=new JTextField("09005433",23);
jpfPW=new JPasswordField("13051682",23);
final JButton btLogOn=new JButton("登录");
final Container con=frmAdimin.getContentPane();
btLogOn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==btLogOn)
{
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ec){
ec.printStackTrace();
}
try{
String user = "";
String password = "";
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=admin.mdb";
con=DriverManager.getConnection(url,user, password);
sql=con.createStatement();
rs=sql.executeQuery("Select * From 管理员 where 工号='"+jtfID.getText().trim()+"' and 密码='"+new String(jpfPW.getPassword())+"'");
isTrue=rs.next();
if(isTrue==true)
{
ServerGUI();
frmAdimin.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"无此用户","提示",JOptionPane.INFORMATION_MESSAGE);
}
}catch(SQLException ec){
ec.printStackTrace();
}
}
}
});
con.setBackground(Color.LIGHT_GRAY);
GridLayout gl=new GridLayout(3,1);
con.setLayout(gl);
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
p2.add(labelID);
p2.add(jtfID);
con.add(p2);
p3.add(labelPW);
p3.add(jpfPW);
con.add(p3);
p4.add(btLogOn);
con.add(p4);
frmAdimin.setVisible(true);
}
void ServerGUI()
{
this.setTitle("管理员界面");
setSize(800, 600);
JPanel jplControl=new JPanel();
JScrollPane jsp1=new JScrollPane(jtaControl);
jplControl.setLayout(new BorderLayout());
jplControl.add(jsp1);
JPanel jplsqlQuery=new JPanel();
JTabbedPane tpSql=new JTabbedPane(2);
tpSql.addTab("会员数据库",new Member_Server());
tpSql.addTab("招标现场", new Application_Server());
tpSql.addTab("招标完成项目", new Item_Server());
tpSql.addTab("商品数据库", new Store_Server());
jplsqlQuery.setLayout(new BorderLayout());
jplsqlQuery.add(tpSql);
JTabbedPane tp=new JTabbedPane();
tp.addTab("控制台",jplControl);
tp.addTab("数据库查看", jplsqlQuery);
getContentPane().add(tp);
this.addWindowListener(this);
setVisible(true);
}
public static void main(String[] Args) throws IOException{
new server();
}
public void windowActivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosed(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosing(WindowEvent arg0) {
frmAdimin.setVisible(true);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowDeiconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowIconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowOpened(WindowEvent arg0) {
// TODO 自动生成方法存根
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -