




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
编写一个简易的聊天器程序,至少提供一个聊天内容显示文本域和一个发送消息的文本框界面,要求实现在发送信息框内填写内容并按下回车后,把该内容添加到上面的文本域内。package com;import java.awt.FlowLayout;import java.awt.LayoutManager;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import javax.swing.*;public class Ltsdemo extends JFrame implements FocusListenerstatic final int f=300;static final int s=300;JLabel l1,l2;JTextArea t1;JTextField t2;JPanel jp1,jp2,jp3;Ltsdemo()super(聊天室程序);jp1=new JPanel();jp2=new JPanel();l1=new JLabel(接收消息);t1=new JTextArea(4,20);JScrollPane s2=new JScrollPane(t1,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);s2.addFocusListener(this);jp1.add(l1);jp1.add(s2);l2=new JLabel(输入消息);t2=new JTextField(发送内容,20);t2.addFocusListener(this);t2.addKeyListener(new KeyAdapter()public void keyPressed(KeyEvent e)if(e.getKeyChar()=n)t1.setText(t1.getText()+n+t2.getText();t2.setText();/文本框清空);jp2.add(l2);jp2.add(t2); FlowLayout f1=new FlowLayout();this.setLayout(f1);this.add(jp1);this.add(jp2);setSize(f,s);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);public static void main(String args)Ltsdemo s1=new Ltsdemo();public void focusGained(FocusEvent e) if(e.getComponent()=t2)t2.setText();/清空文本域;public void focusLost(FocusEvent e) if(e.getComponent()=t2)t2.setText(发送消息);/清空文本域;package COM;import java.awt.FlowLayout;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import javax.swing.*;public class Lts extends JFrame implements FocusListenerJLabel s1,s2,s3;JTextField t1,t2,t3;JTextArea a1;JButton w1, w2;JPanel jp,jp1,jp2,jp3;Lts(String Title)setTitle(聊天室-客户端程序);jp=new JPanel();s1=new JLabel(服务器:);t1=new JTextField(127.0.0.1,20);w1=new JButton( 退出 );jp.add(s1);jp.add(t1);jp.add(w1);s2=new JLabel(端口号:);t2=new JTextField(2000,20);w2=new JButton( 退出 );jp1=new JPanel();jp1.add(s2);jp1.add(t2);jp1.add(w2);jp2=new JPanel();a1=new JTextArea(客户端服务器 2008-8-19 11:36:26 n连接完成 n服务器 2008-8-19 11:36:33 nabc n ,4,7);jp2.add(a1);jp3=new JPanel();s3=new JLabel( 发送 );t3=new JTextField(20);t3.addFocusListener(this);t3.addKeyListener(new KeyAdapter()public void keyPressed(KeyEvent e)if(e.getKeyChar()=n)a1.setText(a1.getText()+n+t3.getText();t3.setText();/文本框清空);jp3.add(s3);jp3.add(t3);FlowLayout f1=new FlowLayout();setLayout(f1);add(jp);add(jp1);add(jp2);add(jp3);setSize(400,400);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);public static void main(String args)Lts ss=new Lts( );public void focusGained(FocusEvent e) if(e.getComponent()=t2)t2.setText();/清空文本域;public void focusLost(FocusEvent e) if(e.getComponent()=t2)t2.setText(发送消息);/清空文本域;package sex;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class Jsqdemo extends JFrame implements ActionListenerJPanel jp,jp1,jp2,jp3,jp4,jp5;JLabel l1;JTextField t1;JButton k1,k2,k3,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15,w16,w17,w18,w19,w20;String s1,s2,s;Jsqdemo()super(计算器);jp=new JPanel();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jp5=new JPanel();l1=new JLabel( 计算结果: );t1=new JTextField(40);jp.setLayout(new GridLayout(1,2);jp.add(l1);jp.add(t1);k1=new JButton( Java );k2=new JButton( Backspack );k3=new JButton(CE);k3.addActionListener(this);jp1.setLayout(new GridLayout(1,3);jp1.add(k1);jp1.add(k2);jp1.add(k3);/jp1.setLayout(new GridLayout(1,3);w1=new JButton(7);w1.addActionListener(this);w2=new JButton(8);w2.addActionListener(this);w3=new JButton(9);w3.addActionListener(this);w4=new JButton(/);w4.addActionListener(this);w5=new JButton(sqrt);w5.addActionListener(this);jp2.setLayout(new GridLayout(1,5);jp2.add(w1);jp2.add(w2);jp2.add(w3);jp2.add(w4);jp2.add(w5);w6=new JButton(4);w6.addActionListener(this);w7=new JButton(5);w7.addActionListener(this);w8=new JButton(6);w8.addActionListener(this);w9=new JButton(*);w9.addActionListener(this);w10=new JButton(%);w10.addActionListener(this);jp3.setLayout(new GridLayout(1,5);jp3.add(w6);jp3.add(w7);jp3.add(w8);jp3.add(w9);jp3.add(w10);w11=new JButton(1);w11.addActionListener(this);w12=new JButton(2);w12.addActionListener(this);w13=new JButton(3);w13.addActionListener(this);w14=new JButton(-);w14.addActionListener(this);w15=new JButton(sin);w15.addActionListener(this);jp4.setLayout(new GridLayout(1,5);jp4.add(w11);jp4.add(w12);jp4.add(w13);jp4.add(w14);jp4.add(w15);w16=new JButton(0);w16.addActionListener(this);w17=new JButton(cos);w17.addActionListener(this);w18=new JButton(.);w18.addActionListener(this);w19=new JButton(+);w19.addActionListener(this);w20=new JButton(=);w20.addActionListener(this);jp5.setLayout(new GridLayout(1,5);jp5.add(w16);jp5.add(w17);jp5.add(w18);jp5.add(w19);jp5.add(w20);this.setLayout(new GridLayout(6,1);this.add(jp);this.add(jp1);this.add(jp2);this.add(jp3);this.add(jp4);this.add(jp5);this.setBounds(200,200,300,300);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setVisible(true);/监测各个按钮public void actionPerformed(ActionEvent event)String str=event.getActionCommand();if(str.equals(.)t1.setText(t1.getText()+.);else if(str.equals(0)t1.setText(t1.getText()+0);else if(str.equals(1)t1.setText(t1.getText()+1);else if(str.equals(2)t1.setText(t1.getText()+2);else if(str.equals(3)t1.setText(t1.getText()+3);else if(str.equals(4)t1.setText(t1.getText()+4);else if(str.equals(5)t1.setText(t1.getText()+5);else if(str.equals(6)t1.setText(t1.getText()+6);else if(str.equals(7)t1.setText(t1.getText()+7);else if(str.equals(8)t1.setText(t1.getText()+8);else if(str.equals(9)t1.setText(t1.getText()+9);else if(str.equals(CE)t1.setText();if(str.equals(sqrt)s1=t1.getText();double d1=Double.parseDouble(s1);t1.setText(+Math.sqrt(d1);if(str.equals(sin)s1=t1.getText();double d1=Double.parseDouble(s1);d1=d1*Math.PI/180;t1.setText(+Math.sin(d1);if(str.equals(cos)s1=t1.getText();double d1=Double.parseDouble(s1);d1=d1*Ma
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电话谈判课件
- 边防船艇知识培训内容课件
- 精准扶贫入户培训
- 村主任培训方案
- 技术运用面试题及答案大全
- 文化旅游资金申请2025年政策导向与应用策略报告
- 工商银行2025景德镇市半结构化面试15问及话术
- 中国银行2025遵义市秋招笔试价值观测评题专练及答案
- 工商银行2025临沂市秋招半结构化面试题库及参考答案
- 2025年3D打印技术的个性化定制应用
- 2024-2030年中国生物质颗粒行业市场发展趋势与前景展望战略分析报告
- 气管插管术评分标准
- 提升护理人员的自我管理能力与情绪控制
- 当代媒介素养 课件 高萍 第1-5讲 媒介素养范畴-受众认知结构与个体差异
- 《预防脊柱侧弯》课件
- 纪律委员竞选课件
- 职业院校技能大赛高职组《电子商务技能》赛项样题4套题库
- 2024年生活污水处理项目管理培训课件
- 《基本医疗卫生与健康促进法》培训
- 古希腊文化与体育
- JCT478.2-2013 建筑石灰试验方法 第2部分 化学分析方法
评论
0/150
提交评论