?? databaseclient.java
字號:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DatabaseClient extends Applet implements Runnable,ActionListener
{
TextField 輸入查詢內(nèi)容;
Choice choice=null;
Checkbox 完全一致,前方一致,后方一致,中間包含;
CheckboxGroup group=null;
Button 查詢;
TextArea 顯示查詢結(jié)果;
Label 提示條;
Socket socket=null;
DataInputStream in=null;
DataOutputStream out=null;
Thread thread;
public void init()
{
輸入查詢內(nèi)容=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);
顯示查詢結(jié)果=new TextArea(8,40);
提示條=new Label("正在連接到服務(wù)器,請稍等...",Label.CENTER);
提示條.setForeground(Color.red);
提示條.setFont(new Font("TimesRoman",Font.BOLD,24));
Panel box1=new Panel();
box1.add(new Label("輸入查詢內(nèi)容:",Label.CENTER));
box1.add(輸入查詢內(nèi)容);
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("查詢結(jié)果:",Label.CENTER));
box3.add(顯示查詢結(jié)果);
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("與服務(wù)器已斷開");
break;
}
顯示查詢結(jié)果.append(s);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==查詢)
{
顯示查詢結(jié)果.setText(null);
String s="";
s=輸入查詢內(nèi)容.getText();
String 范疇=choice.getSelectedItem();
String 條件=group.getSelectedCheckbox().getLabel();
if(s.length()>0)
{
try{
out.writeUTF(s+":"+范疇+":"+條件);
}
catch(IOException e1)
{
提示條.setText("與服務(wù)器已斷開");
}
}
else
{
輸入查詢內(nèi)容.setText("請輸入內(nèi)容");
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -