clientBtn = new Button("客户端"); serverBtn = new Button("服务器");
ta = new TextArea("", 10, 50, TextArea.SCROLLBARS_BOTH); lbl1 = new Label("IP地址:");
tfaddress = new TextField("192.168.1.104", 10); lbl2 = new Label("端口:");
tfport = new TextField("8080"); lbl3 = new Label("发送内容:"); tftype = new TextField(40);
tftype.addKeyListener(new TFListener()); ta.setEditable(false);
//向容器中加入以上组件 setLayout(new FlowLayout()); add(lbl1);
add(tfaddress); add(lbl2); add(tfport); add(clientBtn); add(serverBtn); add(ta); add(lbl3); add(tftype);
//设置格式
setLocation(400, 250); //窗口显示再屏幕的位置坐标 setSize(400, 300); //设置窗体大小 setTitle("基于Socket和多线程编程的聊天程序"); this.setVisible(true); //设置窗体可见 //事件响应
clientBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { port = Integer.parseInt(tfport.getText());
client = new Client(tfaddress.getText(), port, frm); client.start();
tfaddress.setEnabled(false); tfport.setEnabled(false); serverBtn.setEnabled(false); clientBtn.setEnabled(false); } });
serverBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { port = Integer.parseInt(tfport.getText()); server = new Server(port, frm); server.start();
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库Socket和多线程编程的聊天程序实现(7)在线全文阅读。
相关推荐: