📄 databaseclient.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package client;/** * * @author Administrator */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 输入查询内容; 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("请输入内容"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -