用java实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用java实现相关的知识,希望对你有一定的参考价值。
用java实现:
学校图书管理系统(图书类:书号,书名,单价,出版社;借阅者:姓名,借入数量,归还时间,借入时间;),模拟学校图书馆前台借书业务,基本实现借书,还书,维护学生信息等。
学校的作业
不会弄了~快要交了~希望做过的把源代码发给我~越简单越好~我们这水平都不高~弄太复杂了老师也不会信
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DatabaseClient extends Applet implements Runnable,ActionListener
TextField 输入查询内容;
Choice choice=null;
Checkbox 完全一致,前方一致,后方一致,中间包含;
CheckboxGroup group=null;
Button 查询;
TextArea 显示查询结果;
Label 提示条;
Socket socket=null;
DataInputStream in=null;
DataOutputStream out=null;
Thread thread;
public void init()
输入查询内容=new TextField(18);
查询=new Button("查询");
choice=new Choice();
choice.add("书名");
choice.add("作者");
choice.add("出版社");
choice.select(0);
group=new CheckboxGroup();
完全一致=new Checkbox("完全一致",true,group);
前方一致=new Checkbox("前方一致",false,group);
后方一致=new Checkbox("后方一致",false,group);
中间包含=new Checkbox("中间包含",false,group);
显示查询结果=new TextArea(8,40);
提示条=new Label("正在连接到服务器,请稍等...",Label.CENTER);
提示条.setForeground(Color.red);
提示条.setFont(new Font("TimesRoman",Font.BOLD,24));
Panel box1=new Panel();
box1.add(new Label("输入查询内容:",Label.CENTER));
box1.add(输入查询内容);
box1.add(choice);
box1.add(查询);
Panel box2=new Panel();
box2.add(new Label("选择查询条件:",Label.CENTER));
box2.add(完全一致);
box2.add(前方一致);
box2.add(后方一致);
box2.add(中间包含);
Panel box3=new Panel();
box3.add(new Label("查询结果:",Label.CENTER));
box3.add(显示查询结果);
add(提示条);
add(box1);
add(box2);
add(box3);
查询.addActionListener(this);
public void start()
if(socket!=null&&in!=null&&out!=null)
try
socket.close();
in.close();
out.close();
catch(Exception ee)
try
socket=new Socket(this.getCodeBase().getHost(), 6666);
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
catch (IOException ee)
提示条.setText("连接失败");
if(socket!=null)
InetAddress address=socket.getInetAddress();
提示条.setText("连接:"+address+"成功");
if(thread==null)
thread=new Thread(this);
thread.start();
public void stop()
try
socket.close();
thread=null;
catch(IOException e)
this.showStatus(e.toString());
public void run()
String s=null;
while(true)
try
s=in.readUTF();
catch (IOException e)
提示条.setText("与服务器已断开");
break;
显示查询结果.append(s);
public void actionPerformed(ActionEvent e)
if(e.getSource()==查询)
显示查询结果.setText(null);
String s="";
s=输入查询内容.getText();
String 范畴=choice.getSelectedItem();
String 条件=group.getSelectedCheckbox().getLabel();
if(s.length()>0)
try
out.writeUTF(s+":"+范畴+":"+条件);
catch(IOException e1)
提示条.setText("与服务器已断开");
else
输入查询内容.setText("请输入内容");
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.StringTokenizer;
public class DatabaseServer
public static void main(String args[])
ServerSocket server=null;
Server_thread thread;
Socket you=null;
while(true)
try
server=new ServerSocket(6666);
catch(IOException e1)
System.out.println("正在监听");
try
you=server.accept();
catch (IOException e)
if(you!=null)
new Server_thread(you).start();
else continue;
class Server_thread extends Thread
Socket socket;
Connection con=null;
Statement stmt=null;
ResultSet rs;
DataOutputStream out=null;
DataInputStream in=null;
String s=null;
int number=0;
Server_thread(Socket t)
socket=t;
try
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
catch (IOException e)
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(ClassNotFoundException e)
try
con=DriverManager.getConnection("jdbc:odbc:moon","","");
stmt=con.createStatement();
catch(SQLException ee)
public void run()
while(true)
try
s=in.readUTF();
System.out.println(s);
String sqlCondition=null;
String 查询内容="",查询范畴="",查询条件="";
StringTokenizer fenxi=new StringTokenizer(s,":");
if(fenxi.hasMoreTokens())
查询内容=fenxi.nextToken();
if(fenxi.hasMoreTokens())
查询范畴=fenxi.nextToken();
if(fenxi.hasMoreTokens())
查询条件=fenxi.nextToken();
if(查询条件.equals("完全一致"))
sqlCondition=
"SELECT * FROM bookform WHERE "+查询范畴+" = "+"'"+查询内容+"' ";
else if(查询条件.equals("前方一致"))
sqlCondition=
"SELECT * FROM bookform WHERE "+查询范畴+" LIKE "+"'"+查询内容+"%' ";
else if(查询条件.equals("后方一致"))
sqlCondition=
"SELECT * FROM bookform WHERE "+查询范畴+" LIKE "+"'%"+查询内容+"' ";
else if(查询条件.equals("中间包含"))
sqlCondition=
"SELECT * FROM bookform WHERE "+查询范畴+" LIKE "+"'%"+查询内容+"%' ";
try
rs=stmt.executeQuery(sqlCondition);
number=0;
while(rs.next())
number++;
String 书名=rs.getString("书名");
String 作者=rs.getString("作者");
String 出版社=rs.getString("出版社");
String 价格=rs.getString("价格");
Date 日期=rs.getDate("日期");
out.writeUTF("\n"+number+" "+书名+" , "+作者+","+出版社+","+价格+
","+日期);
if(number==0)
out.writeUTF("没有查询到任何记录\n");
catch(SQLException ee)
catch (IOException e)
try
socket.close();
con.close();
catch(Exception eee)
System.out.println("客户离开了");
break;
参考技术A BS一下 参考技术B 你BS个P啊,人家做不出来,来求你们,你们鄙视什么啊?我看该鄙视的是你们。
楼主,对不起哦,我只有C++的,没有java的,帮补了你 参考技术C 我很想做,不过我才刚学JAVA不久.应该是不会的.好多都没有学呢.
电子签名用Java怎么实现
电子签名用Java怎么实现
参考技术A import java.security.InvalidKeyException;import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* ECDSA 160bit 签名及签名验证例子
*/
public class ECDSASignature
public static void main(String argv[])
signatureTest();
public static void signatureTest()
/**
* 密钥对生成
*/
KeyPairGenerator keyPairGenerator = null;
try
keyPairGenerator = KeyPairGenerator.getInstance("EC");
catch (NoSuchAlgorithmException ex)
return;
SecureRandom secureRandom = new SecureRandom();
keyPairGenerator.initialize(160, secureRandom);
KeyPair pair = keyPairGenerator.generateKeyPair();
Key publicKey = pair.getPublic();
Key privateKey = pair.getPrivate();
// 字符串
String hako = "test";
/**
* 私钥签名(ECDSA 160bit)
*/
byte[] sign = null;
try
Signature signatureSign = null;
signatureSign = Signature.getInstance("NONEwithECDSA");
signatureSign.initSign((PrivateKey) privateKey, secureRandom);
signatureSign.update(hako.getBytes());
sign = signatureSign.sign();
System.out.println("sign: " + new String(sign));
catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException ex)
Logger.getLogger(ECDSASignature.class.getName()).log(Level.SEVERE, null, ex);
/**
* 用公钥进行签名验证
*/
Signature signatureVerify = null;
try
signatureVerify = Signature.getInstance("NONEwithECDSA");
signatureVerify.initVerify((PublicKey) publicKey);
signatureVerify.update(hako.getBytes());
boolean verifyResult = signatureVerify.verify(sign);
System.out.println(verifyResult ? "签名OK" : "签名NG");
catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e)
Logger.getLogger(ECDSASignature.class.getName()).log(Level.SEVERE, null, e);
参考技术B 需要买第三方控件吧!http://www.huuinn.com/java-%E7%94%B5%E5%AD%90%E7%AD%BE%E5%90%8D%E8%8C%83%E4%BE%8B%E4%BB%A3%E7%A0%81/
以上是关于用java实现的主要内容,如果未能解决你的问题,请参考以下文章