📄 clientcontrol1.java
字号:
import java.applet.Applet;
import java.awt.Button;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
/*
* Created on 2006-3-16
* applet程序, 与javascript进行通信,来控制云台的转动;
* 与服务器端的server程序通信,发送云台的控制码;
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class clientcontrol1 extends Applet {
private Button button = null;
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private static Socket socket;
private static PrintStream out;
private static String string;
/**
* This is the default constructor
*/
public clientcontrol1() {
super();
init();
try {
socket = new Socket("10.1.37.220",8765);
System.out.print("socket8765 ok!\n");
out = new PrintStream(socket.getOutputStream());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setLayout(null);
this.setPreferredSize(new java.awt.Dimension(460,70));
this.setMinimumSize(new java.awt.Dimension(460,70));
this.setSize(437, 31);
this.add(getButton(), null);
this.add(getButton1(), null);
this.add(getButton2(), null);
this.add(getButton3(), null);
this.add(getButton4(), null);
}
/**
* This method initializes button
*
* @return java.awt.Button
*/
private Button getButton() {
if (button == null) {
button = new Button();
button.setLabel("UP");
button.setLocation(8, 1);
button.setSize(70, 30);
button.setName("up");
button.setForeground(java.awt.Color.blue);
button.setBackground(new java.awt.Color(255,204,204));
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
out.flush();
string="u";
System.out.print("string:"+string);
out.println(string);
System.out.print("write ok!\n");
}
});
}
return button;
}
/**
* This method initializes button1
*
* @return java.awt.Button
*/
private Button getButton1() {
if (button1 == null) {
button1 = new Button();
button1.setLabel("DOWN");
button1.setLocation(98, 1);
button1.setSize(70, 30);
button1.setName("down");
button1.setBackground(new java.awt.Color(255,204,204));
button1.setForeground(java.awt.Color.blue);
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
out.flush();
string="d";
System.out.print("string:"+string);
out.println(string);
System.out.print("write ok!\n");
}
});
}
return button1;
}
/**
* This method initializes button2
*
* @return java.awt.Button
*/
private Button getButton2() {
if (button2 == null) {
button2 = new Button();
button2.setLabel("LEFT");
button2.setLocation(185, 0);
button2.setSize(70, 30);
button2.setName("left");
button2.setBackground(new java.awt.Color(255,204,204));
button2.setForeground(java.awt.Color.blue);
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
out.flush();
string="l";
System.out.print("string:"+string);
out.println(string);;
System.out.print("write ok!\n");
}
});
}
return button2;
}
/**
* This method initializes button3
*
* @return java.awt.Button
*/
private Button getButton3() {
if (button3 == null) {
button3 = new Button();
button3.setLabel("RIGHT");
button3.setLocation(274, 1);
button3.setSize(70, 30);
button3.setName("right");
button3.setBackground(new java.awt.Color(255,204,204));
button3.setForeground(java.awt.Color.blue);
button3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
out.flush();
string="r";
System.out.print("string:"+string);
out.println(string);
System.out.print("write ok!\n");
}
});
}
return button3;
}
/**
* This method initializes button4
*
* @return java.awt.Button
*/
private Button getButton4() {
if (button4 == null) {
button4 = new Button();
button4.setLabel("STOP");
button4.setLocation(364, 0);
button4.setSize(70, 30);
button4.setName("stop");
button4.setBackground(new java.awt.Color(255,204,204));
button4.setForeground(java.awt.Color.blue);
button4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
out.flush();
string="s";
System.out.print("string:"+string);
out.println(string);
System.out.print("write ok!\n");
}
});
}
return button4;
}
} // @jve:decl-index=0:visual-constraint="14,30"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -