第一个java的小东东

第一个java的小东东,还很弱智的,不过会变强的,

  1. /**
  2. 用到map,和awt;
  3. 下一版本要增加,更多属性,用到问文件的读写,对话框
  4. 问题:文本框双击异常没解决  
  5.  */
  6. import java.awt.*;
  7. import java.awt.event.*;
  8. import java.util.*;
  9. public class TongXunLu{
  10.     Map <String,String> map=new HashMap<String,String>();
  11.         TextField t1=new TextField(10);
  12.         TextField t2=new TextField(10);
  13.         TextField t3=new TextField(10);
  14.         TextField t4=new TextField(10);
  15.         
  16.         TextArea ta=new TextArea("",5,3,1 );
  17.         
  18.     
  19.         
  20.         
  21.     public TongXunLu() {
  22.         Frame f=new Frame("电话本1.0(EKOI)");
  23.         //f.setSize(600,400);
  24.         f.setVisible(true);
  25.         f.setLayout(new GridLayout(3,0));
  26.         Panel p1=new Panel();
  27.         Panel p2=new Panel();
  28.         
  29.         
  30.         p1.setLayout(new FlowLayout());
  31.         p2.setLayout(new FlowLayout());
  32.         ta.setEditable(false);//*********
  33.     
  34.         Label l1=new Label("name");
  35.         Label l2=new Label("number");
  36.         
  37.         Label l3=new Label("name");
  38.         Label l4=new Label("number");   
  39.     
  40.         
  41.     
  42.         
  43.         Button b1=new Button("add");
  44.         Button b2=new Button("search");
  45.         Button b3=new Button("all item");
  46.         
  47.         b1.addActionListener(new B1Lister());
  48.         b2.addActionListener(new B2Lister());
  49.         b3.addActionListener(new B3Lister());
  50.         
  51.         p1.add(l1);
  52.         p1.add(t1);
  53.         p1.add(l2);
  54.         p1.add(t2);
  55.         p1.add(b1);
  56.         f.add(p1);
  57.         
  58.         p2.add(l3);
  59.         p2.add(t3);
  60.         
  61.     
  62.         p2.add(b2);
  63.         p2.add(b3);
  64.         f.add(p2);
  65.         f.add(ta);
  66.         f.setResizable(false);
  67.         f.pack();
  68.         
  69.         
  70.         
  71.         
  72.         
  73.         
  74.         
  75.         
  76.         
  77.         f.addWindowListener(new WindowAdapter()
  78.         {
  79.         
  80.             public void windowClosing(WindowEvent e) 
  81.             {
  82.                 System.exit(-1);
  83.             }
  84.         }
  85.             );
  86.         
  87.     }
  88.     
  89.     public static void main(String []args) throws Exception
  90.     {
  91.         new TongXunLu();
  92.     }
  93.     
  94.     class B1Lister implements ActionListener
  95.     {
  96.          public void actionPerformed(ActionEvent e) 
  97.         {
  98.             String str=t1.getText();
  99.             
  100.             String num=t2.getText();
  101.             t1.setText("");
  102.             t2.setText("");
  103.             map.put(str,num);
  104.             ta.setText("");
  105.             ta.setText("insert ok");
  106.             
  107.             
  108.             
  109.         }
  110.     }
  111.     
  112.     class B2Lister implements ActionListener
  113.     {
  114.         public void actionPerformed(ActionEvent e)
  115.         {
  116.             String str=null;
  117.             String num;
  118.             str=t3.getText();
  119.             t3.setText("");
  120.             num=map.get(str);
  121.             ta.setText("");
  122.             if(num==null)
  123.                 ta.setText("对不起,没有记录");
  124.                 else    
  125.             ta.setText("name: "+str+"/nnum:"+num);
  126.             
  127.             
  128.             
  129.             
  130.             
  131.         }
  132.     }
  133.     
  134.     class B3Lister implements ActionListener
  135.     {
  136.         public void actionPerformed(ActionEvent e)
  137.         {
  138.             //Collection <String> c=map.values();
  139.             ta.setText("");
  140.             String str=map.toString();
  141.             String str1=str.substring(1,str.length()-1);
  142.             String[] end=str1.split(",");
  143.             forint i=0; i<end.length; i++)
  144.             {
  145.                 String []t=end[i].split("=");
  146.                 ta.append("name:"+t[0]+" number:"+t[1]+"/n");
  147.                 
  148.                 //System.out.println("name:"+t[0]+" number:"+t[1]);
  149.             }
  150.             
  151.         }
  152.             
  153.     }
  154.     
  155.   class Dis
  156.   {
  157.     String name;
  158.     int num;
  159.   }
  160. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值