📄 subadd.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 subAdd extends Applet implements Runnable,ActionListener
{
TextField txt_subno;
TextField txt_subname;
Label lab_subno;
Label lab_subname;
Button btn_add=new Button();
Label tishi;
Label xianshi;
Socket socket=null;
DataInputStream in=null;
DataOutputStream out=null;
Thread thread;
public void init(){
txt_subno=new TextField(10);
txt_subname=new TextField(10);
lab_subno=new Label("科目编号",Label.CENTER);
lab_subname=new Label("科目",Label.CENTER);
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();
Panel box3=new Panel();
Panel box4=new Panel();
Panel box5=new Panel();
box1.add(new Label("输入添加内容:",Label.CENTER));
box2.add(xianshi);
box3.add(lab_subno);
box3.add(txt_subno);
box4.add(lab_subname);
box4.add(txt_subname);
box1.add(btn_add);//又添加
add(tishi);
add(box1);
add(box3);
add(box4);
add(box5);
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(), 6667);
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="",s2="";
String tianjia=btn_add.getLabel();//有写的
s1=txt_subno.getText();
s2=txt_subname.getText();
String str=s1+","+s2;
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 + -