📄 stufind.java
字号:
/*
* Created on 2005-12-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author tian
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class stuFind 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;
PrintWriter pw=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(20,100);
提示条=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(), 6664);
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
pw = new PrintWriter(out,true);
}
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 + -