📄 testframe.java~8~
字号:
package client;import java.awt.*;import javax.swing.*;import java.awt.event.*;/** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */public class TestFrame extends Panel{ TextArea textArea1 = new TextArea(); MyClient m_socket=null; Label label1 = new Label(); TextField textField1 = new TextField(); Button button1 = new Button(); public TestFrame() { try { jbInit(); m_socket=new MyClient("sxf",this); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { TestFrame testFrame1 = new TestFrame(); Frame f=new Frame("聊天"); f.setSize(470,320); f.add(testFrame1); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.show(); } private void jbInit() throws Exception { this.setLayout(null); textArea1.setBounds(new Rectangle(18, 16, 426, 219)); label1.setText("请输入现在要发送的消息"); label1.setBounds(new Rectangle(18, 256, 133, 18)); textField1.setBounds(new Rectangle(164, 256, 190, 22)); button1.setLabel("发送"); button1.setBounds(new Rectangle(374, 254, 75, 29)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.add(textArea1, null); this.add(label1, null); this.add(textField1, null); this.add(button1, null); } private void sendText(String str) { if(m_socket==null)return; m_socket.writeStr(str); } public void readStr(String str) {// textArea1.setForeground(Color.green); textArea1.append("You say:"+str+"\n"); } public void showMessage(String str) {// textArea1.setForeground(Color.black); textArea1.append("You say:"+str+"\n"); } void button1_actionPerformed(ActionEvent e) { String str=jTextField1.getText().trim(); sendText(str);// textArea1.setForeground(Color.red); textArea1.append("I say:"+str+"\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -