?? studel.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.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class stuDel extends Applet implements Runnable,ActionListener
{
TextField txt_no;
Button btn_add=new Button();
Label tishi;
Label xianshi;
Socket socket=null;
DataInputStream in=null;
DataOutputStream out=null;
Thread thread;
public void init(){
txt_no=new TextField(10);
btn_add=new Button("刪除");//又刪除
tishi=new Label("正在連接到服務器,請稍等...",Label.CENTER);
tishi.setForeground(Color.red);
tishi.setFont(new Font("TimesRoman",Font.BOLD,24));
xianshi=new Label("提示結果");
Panel box1=new Panel();
Panel box2=new Panel();
box1.add(new Label("輸入刪除學號:",Label.CENTER));
box2.add(xianshi);
box1.add(txt_no);
box1.add(btn_add);//又刪除
add(tishi);
add(box1);
add(box2);
btn_add.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(), 6662);
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
}
catch (IOException ee)
{
tishi.setText("連接失敗");
}
if(socket!=null)
{
InetAddress address=socket.getInetAddress();
tishi.setText("連接:"+address+"成功");
}
if(thread==null)
{
thread=new Thread(this);
thread.start();
}
}
public void run(){
String s=null;
while(true)
{
try{
s=in.readUTF();
}
catch (IOException e)
{
tishi.setText("與服務器已斷開");
break;
}
xianshi.setText("刪除成功");
}
}
//..........
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn_add)
{
String s1="";
String tianjia=btn_add.getLabel();//有寫的
s1=txt_no.getText();
String str=s1;
if(str.length()>0)
{
try{
out.writeUTF(str);
}
catch(IOException e1)
{
tishi.setText("與服務器已斷開");
}
}
else
{
xianshi.setText("刪除成功");
}
}
}
//............
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -