鼠标失去焦点窗口不能关闭 求救 详细一点最好

动天丶 2015-08-07 11:29:30
package com.server;

import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Text {
static String NUM = null;
static String P_0 = null;
static String P_1 = null;
static String TEM = null;
static String HUM = null;
static String IR = null;
static String len = null;
private static Socket s;
private static BufferedReader br;
private static String line = "";

public static String Client() {
try {
s = new Socket("192.168.2.1", 8000);
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
line = br.readLine();
br.close();
} catch (IOException ie) {
ie.printStackTrace();
}
return line;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final Frame nw = new Frame("家庭管理");
Panel nn = new Panel();
nn.setLayout(null);
Button n1 = new Button("开始接收");
final TextField b1 = new TextField();
final TextField b2 = new TextField();
final TextField b3 = new TextField();
final TextField b4 = new TextField();
final TextField b5 = new TextField();
final TextField b6 = new TextField();
Label a1 = new Label("服务器IP:");
Label a2 = new Label("设 备IP:");
Label a3 = new Label("数 据1:");
Label a4 = new Label("数 据2:");
Label a6 = new Label("数 据3:");
Label a5 = new Label("数 据 报:");
n1.setBounds(460, 210, 100, 40);
b1.setBounds(130, 20, 150, 30);
b2.setBounds(130, 70, 150, 30);
b3.setBounds(130, 120, 150, 30);
b4.setBounds(130, 170, 150, 30);
b5.setBounds(130, 220, 150, 30);
b6.setBounds(400, 20, 150, 30);
a1.setBounds(40, 70, 60, 30);
a2.setBounds(40, 120, 60, 30);
a3.setBounds(40, 170, 60, 30);
a4.setBounds(40, 220, 60, 30);
a5.setBounds(40, 20, 60, 30);
a6.setBounds(340, 20, 60, 30);
nn.add(a1);
nn.add(a2);
nn.add(a3);
nn.add(a4);
nn.add(a5);
nn.add(a6);
nn.add(b6);
nn.add(b1);
nn.add(b2);
nn.add(b3);
nn.add(b4);
nn.add(b5);
nn.add(n1);
nw.setSize(600, 320);
nw.setLocationRelativeTo(null);
nw.add(nn);
nw.setVisible(true);
nw.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
n1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(;;)
{
NUM = Client();
len = NUM.substring(4, 6);
if (len.equals("11")) {
P_0 = NUM.substring(6, 8);
P_1 = NUM.substring(8, 10);
TEM = NUM.substring(10, 12);
HUM = NUM.substring(12, 14);
IR = NUM.substring(14, 15);
b1.setText(NUM);
b2.setText(P_0);
b3.setText(P_1);
b4.setText(TEM);
b5.setText(HUM);
b6.setText(IR);
} else {
System.exit(0);
}
}
}
});
}
}
...全文
125 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
动天丶 2015-08-08
  • 打赏
  • 举报
回复
顶一个 求助啊

50,639

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧