日期:2014-05-20 浏览次数:20706 次
import java.awt.BorderLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Control_UI10 extends JFrame {
/**
* @author lyy
*
*/
private static final long serialVersionUID = -37927920298166521L;
private JFrame frame;
JTextField show = new JTextField(10);
Box vtempall = Box.createVerticalBox();
Box midsize = Box.createHorizontalBox();
Box midsize1 = Box.createHorizontalBox();
public static void main(String[] args) {
new Control_UI10();
}
public Control_UI10() {
frame = new JFrame();
frame.setTitle("小车控制");
frame.setLocation(300, 150);
frame.setSize(780, 470);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
// this.setResizable(false);
frame();
// 为窗口增加这个事件
MYKeyLisenter my = new MYKeyLisenter();
frame.addKeyListener(my);
frame.setVisible(true);
}
public void frame() {
// 添加status()类
midsize.add(new status().Status());
// 添加Myview()
midsize.add(new Myview().view());
vtempall.add(midsize);
// 添加control()类
midsize1.add(new control().Control());
// 添加hearing()类
midsize1.add(new hearing().Hearing());
vtempall.add(midsize1);
show.setEditable(false);
show.setText("链接状态:");
vtempall.add(show, BorderLayout.NORTH);
frame.add(vtempall);
}
// 创建键盘监听
public class MYKeyLisenter extends KeyAdapter {
@Override
public void keyPressed(KeyEvent ef) {
super.keyPressed(ef);
switch (ef.getKeyCode()) {
case KeyEvent.VK_UP:
System.out.println("上");
break;
case KeyEvent.VK_DOWN:
System.out.println("下");
break;
case KeyEvent.VK_LEFT:
System.out.println("左");
break;
case KeyEvent.VK_RIGHT:
System.out.println("右");
break;
}
}
}
}
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class control extends JFrame {
private static final long serialVersionUID = 5388121425052483138L;
JButton leye, reye, up, down, left, right, sound, controls, connet;
Box control;
Box vtemp1, htemp4, htemp5, htemp6;
JComboBox jcb;
// ActionListener mb;
JFrame jFrame1;
public static void main(String[] args) {
new control();
}
public control() {
jFrame1 = new JFrame("control");
jFrame1.setLocation(73, 100);