图书管数据库查询系统---客户端部分_shoping & programing_百度空间
 因为时间有限,暂时只实现了部分功能,可能会在以后的时间里进行补充和改进界面。

 

客户端,可以实现对服务器端的局域网访问。

 

整个客户端分成 5个类实现 分别实现 主菜单,查询,登入,借阅登记功能。

其他功能由于时间限制还没实现,但在服务器端已有相应的处理程序。

 

类Client.java

 

 

//import java.awt.*;
//import java.awt.Event;
//import javax.swing.*;
import java.net.*;
//import java.io.*;

public class Client
{

public static void main( String ags[])
{
try
{
Socket So = new Socket("localhost",5000);
PrimaryFrame app = new PrimaryFrame("Example",So);
app.run();   
}
catch( Exception e)
{
}  
}

}

 

类PrimaryFrame.java 主菜单

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

class PrimaryFrame extends JFrame
{
private Socket So;
private BufferedReader in;
private PrintWriter out;
private int PeopleLever;
private JButton[] bu = new JButton[6];
public PrimaryFrame( String name , Socket p)
{
//JFrame app = new JFrame("Example");
super(name);

try
{  
So = p;
in = new BufferedReader( new InputStreamReader( So.getInputStream()));
out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(So.getOutputStream())),true);
}
catch( Exception x)
{}

Container con = this.getContentPane();
//con.setLayout(null);
con.setLayout(new GridLayout( 10 , 10  ) );

//bu[0] = new JButton();
bu[0] = new JButton("连接");
con.add( bu[0] );

//bu[1] = new JButton();
bu[1] = new JButton("查询");
bu[1].setEnabled(false);
con.add( bu[1] );

//bu[2] = new JButton();
bu[2] = new JButton("借书登记");
bu[2].setEnabled(false);
con.add( bu[2] );

//bu[3] = new JButton();
bu[3] = new JButton("还书登记");
bu[3].setEnabled(false);
con.add( bu[3] );

//bu[4] = new JButton();
bu[4] = new JButton("书籍入库");
bu[4].setEnabled(false);
con.add( bu[4] );

//bu[5] = new JButton();
bu[5] = new JButton("书籍出库");
bu[5].setEnabled(false);
con.add( bu[5] );

this.setSize(300, 200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

}

public void run()
{
bu[0].addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{    
//登陆界面
Login Lo = new Login("登入",So,bu);
Lo.runn();
//PeopleLever = Lo.flag;    
}
}
);
bu[1].addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//查询界面    
Query Qu = new Query( "查询",So);
Qu.run();
}
}
);
bu[2].addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//借书界面

Borrow Bo = new Borrow( "借书" , So );
Bo.run();
}
}
);
bu[3].addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//还书界面
}
}
);
bu[4].addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//书籍登记入库界面
}
}
);
bu[5].addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//书籍登记出库界面
}
}
);  

}
}

类 Query.java 查询菜单

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;

class Query extends JFrame
{
private Socket So;
private BufferedReader in;
private PrintWriter out;
private String BookName;
private JButton bu;
private JTextField TField;
private JTextArea TArea;

public Query( String name , Socket p )
{
super(name);

try
{
So = p;
out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( So.getOutputStream()) ),true);
in = new BufferedReader( new InputStreamReader( So.getInputStream()));
Container con = this.getContentPane();
con.setLayout( new BorderLayout());

BookName = new String("书名    ");
TField = new JTextField( BookName );
bu = new JButton(" 确定 ");
TField = new JTextField();
TArea = new JTextArea("BookId BookName BookWriter BookAmount BookCanBorrow BookTime\n",1,10);
TArea.setSize(400, 200);
TArea.setEnabled( false );
con.add( TField ,BorderLayout.NORTH );
con.add( bu ,BorderLayout.SOUTH );
con.add( new JScrollPane( TArea ) ,BorderLayout.CENTER );

this.resize(600,600);
this.setVisible( true );
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch(Exception x)
{}
}

public void run()
{
TField.addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
BookName = e.getActionCommand();
}
}
);
bu.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//输出
try
{
String temp;
BookName = TField.getText();
out.println("2");
out.println( BookName );
temp = in.readLine();
int i = 1;
//TArea.insert("BookId BookName BookWriter BookAmount BookCanBorrow BookTime\n",1,10);

while(temp.compareTo("End result") != 0 )
{
//列表
//把结果大打入TArea中
if(i == 7)
{
TArea.append("\n");
i = 1;
}
//TArea.insert(,i);
TArea.append(temp+"           ");
i++;
temp = in.readLine();
}
TArea.append("\n");
}
catch( Exception x)
{}
}
}
);

}

}

 

类 Login.java 登陆菜单

 

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.net.*;
import java.io.*;

class Login extends JFrame
{
private Socket So;
private BufferedReader in;
private PrintWriter out;
private String ID;
private String Password;
private JTextField []Text = new JTextField[2];
private JButton bu;
private JButton[] bu1;
int flag;

public Login( String name ,Socket p , JButton bu2[] )
{  
super( name );
So = p;
bu1 = bu2;
try
{
in = new BufferedReader( new InputStreamReader(So.getInputStream()));    
out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( So.getOutputStream())),true);
}
catch( Exception e)
{
}

ID = new String("");
flag = -1;
Password = new String("");
Container con = this.getContentPane();
con.setLayout( new GridLayout(5,6));

Text[0] = new JTextField("ID         ");
Text[1] = new JPasswordField("Password");
bu = new JButton("确定");
con.add( Text[0] );
con.add( Text[1] );
con.add(bu);

this.setSize(300,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void runn()
{
//boolean temp = false;

Text[0].addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( e.getSource() == Text[0] )
ID = e.getActionCommand();
}
}
);
Text[1].addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
if( e.getSource() == Text[1] )
Password = e.getActionCommand();    
}
}
);
bu.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//输出ID,Password,验证
String temp;
ID = Text[0].getText();
Password = Text[1].getText();
out.println("1");
out.println(ID);
out.println(Password);
try
{
temp = in.readLine();
if( temp.compareTo("OK") == 0)
{
temp = in.readLine();
if( temp.compareTo("admin") == 0 )
{
flag = 0;
}
else
flag = 1;
}
else
flag = 2;
if( flag ==0 )//管理员登入
{
bu1[1].setEnabled(true);
bu1[2].setEnabled(true);
bu1[3].setEnabled(true);
bu1[4].setEnabled(true);
bu1[5].setEnabled(true);
}
else
if( flag == 1 )//非管理员登入
{
bu1[1].setEnabled(true);
}
else
if( flag == 2)
JOptionPane.showMessageDialog(null, "帐号/密码错误");
if( flag != -1)
{
JOptionPane.showMessageDialog(null, "登陆成功");
setVisible(false);
}      
}
catch( Exception ex )
{}
//flag = 0;//管理员通过验证
//flag = 1;//非管理员通过验证
//flag = 2;//不通过验证
}
}
);


}

类 Borrow.java 借书功能实现

 

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.net.*;
import java.io.*;

class Borrow extends JFrame
{
private Socket So;
private BufferedReader in;
private PrintWriter out;
private String BookId;
private String PeopleId;
private JButton bu;
//private JButton bu1;
private JTextField TField;
private JTextField TField1;
//private JTextArea TArea;

public Borrow( String name , Socket p )
{
super(name);

try
{
So = p;
out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( So.getOutputStream()) ),true);
in = new BufferedReader( new InputStreamReader( So.getInputStream()));
Container con = this.getContentPane();
con.setLayout( new FlowLayout() );

BookId = new String("书籍编号         ");
PeopleId = new String("人物编号       ");   
TField = new JTextField( BookId );
bu = new JButton(" 确定 ");
TField = new JTextField( BookId );
TField1 = new JTextField( PeopleId );
//TArea = new JTextArea();
//TArea.setSize(400, 200);
//TArea.setEnabled( false );

con.add( TField1 );
con.add( TField );
con.add( bu );

//con.add( new JScrollPane( TArea ) );  
this.resize(300,300);
this.setVisible( true );
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
catch(Exception x)
{}
}

public void run()
{
TField.addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
BookId = e.getActionCommand();
}
}
);

TField1.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
PeopleId = e.getActionCommand();
}
}
);

bu.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
//输出
BookId = TField.getText();
PeopleId = TField1.getText();
out.println("5");
out.println(BookId);
out.println(PeopleId);
JOptionPane.showMessageDialog(null, "登记成功");
}
}
);



}

}


郑重声明:资讯 【图书管数据库查询系统---客户端部分_shoping & programing_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——