java计算器小程序.docx
编写一个简易的聊天器程序,至少提供一个聊天内容显示文本域和一个发送消息的文本框界面,要求实现在发送信息框内填写内容并按下回车后,把该内容添加到上面的文本域内。package com;import java. awt. Flowl.ayout;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 FocusListener(static final int /=300;static final int 5=300;JLabel 11,12;JTextArea tl;JTextField t2;JPanel jpl, jp2, jp3;Ltsdemo ()super (聊天室程序);jpl=new JPanel();jp2-new JPanel ();H=new JLabel (接收消息);tl=new JTextArea(4, 20);JScrollPane s2-newJScrollPane(t 1, ScrollPaneConstants. VERTICAL SCROLLBAR ALWAYS, ScrollPaneConstants. HORIZONTAJSCROLLBAR ALWAYS);s2. addFocusLi stener(this);jpl. add (11);jpl. add(s2);12=new JLabel (输入消息”);t2=new JTextField("发送内容,20);t2. addFocusListener(this);t2. addKeyListener(new KeyAdapter()public void keyPressed(KeyEvent e)(if (e. getKeyChar () =, n )11. setText (t 1. getText () +"n"+t2 getText ();t2. setText C");文本框清空);jp2. add (12);jp2. add (t2);FlowLayout fl=new FlowLayout ();this. setLayout(fl);this, add(jpl);this, add (jp2);setSize (/; s);set Def au 11C1 ose0perat i on EX1 T ON_CLOS0 ;setVisible(true);)public static void main(String args)(Ltsdemo sl=new Ltsdemo();)public void focusGained (FocusEvent e) if (e. getComponent () =t2)(t2. setText (z,);清空文本域;)public void focusLost(FocusEvent e) if (e. getComponent () =t2)t2. setText (发送消息);/./清空文本域;接收消息JJ ><J立天室程序输入消息发送内容JL JL D WD L JUJIipUJLIDJLIL ?L 乙/package COM;import java.awt. FlowLayout;import java. awt. event. FocusEvent;import java. awt. event. FocusIJ stener;import java. awt. event. KeyAdapter;importent. KeyEvent;import javax. swing. *;public class Lts extends JFrame implements FocusListenerJLabel sl,s2, s3;JTextField t1,t2,t3;JTextArea al;JButton wl, w2;JPanel jp, jpl, jp2, jp3;Lts(String Title)(setTitle(聊天室-客户端程序);jp=new JPanel0;sl=new JLabel ("服务器:”);tl=new JTextField(,127. 0. 0. 1, 20);wl=new JButton(* 退出);jp. add(sl);jp. add(tl);jp. add(wl);s2=new JLabel ("端口号:");t2=new JTextFieldC2000/z, 20);w2=new JButtonC 退出”);jpl=new JPanel();jpl. add(s2);jpl. add(t2);jpl. add(w2);jp2=new JPanel ();al=new JTextArea("客户端服务器 2008-8-19 11: 36: 26n连接完成n服务器 2008-8-19 11: 36: 33 nabc n" ,4,7);jp2. add(al);jp3=new JPanel ();s3=new JLabel (z,发送");t3=new JTextField(20);t3. addFocusListener(this);t3. addKeyListener(new KeyAdapter()(public void keyPressed(KeyEvent e)if (e. getKeyChar()=, n,)al. setText (al. getText () +"n"+t3. getText ();t3. setText C");文本框清空);jp3. add (s3);jp3. add (t3);FlowLayout fl=new FlowLayout();setLayout(fl);add(jp);add(jpl);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)(12. setTextC");清空文本域;public void focusLost(FocusEvent e) if (e getComponent () =t2)t2. setText(“发送消息);清空文本域;天室程序Jl ×J接收消息asdsafdsf输入消息输入消息 发送消息实现筒单的计算器的功!怎可课后完成Q。package sex;import javaawt. *;import java .awtevent-ActionEvent;import java.awtevent eActionListener;import j avaxswing. *;public class Jsqdemo extends JFrame implements ActionListenerJPanel jp,jpl,jp2,jp3,jp4,jp5;JLabel 11;JTextField tl;JButton kl,k2,k3z wlz w2,w3,w4 w5 w6z w7,w8z w9 wl,w11w12zw13w14zw15zw16w17zw18w19zw20String si,s2,s;Jsqdemo()super ("计算器”);jp=new JPanel();jpl=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jp5=new JPanel();ll=new JLabel ( 计算结果:,f);tl=new JTextField(40);jp.setLayout(new GridLayout(1,2);jp. add(11);jp. add(tl);kl=new JButton (,f Java ,l);k2=new JButton( Backspack );k3=new JButton (',CEn);k3addActionListener(this);jpl.setLayout(new GridLayout(1,3);jpl add(kl);jpladd(k2);jpladd(k3);/jpl.setLayout(new GridLayout(1,3);wl=new JButton (,7 );wladdActionListener(this);w2=new JButton(8n);w2addActionListener(this);w3=ew JButton (, 9 );w3.addActionListener(this);w4=new JButton (',);w4addActionListener(this);w5=new JButton (lf sqrtlf);w5.addActionListener(this);jp2setLayout(new GridLayout(1,5);jp2add(wl);jp2add(w2);jp2. add(w3);jp2add(w4);jp2add(w5);w6=new JButton (',4);w6addActionListener(this);w7=new JButton (,5 );w7.addActionListener(this);w8=new JButton (,6);w8addActionListener(this);w9=new JButton( * n);w9.addActionListener(this);wl=new JButton (f,%lt);wl.addActionListener(this);jp3setLayout(new GridLayout(1,5);jp3add(w6);jp3 , add(w7);jp3add(w8);jp3add(w