第一个java的小东东

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

  1. /**
  2. 用到map,和awt;
  3. 下一版本要增加,更多属性,用到问文件的读写,对话框
  4. 问题:文本框双击异常没解决
  5. */
  6. importjava.awt.*;
  7. importjava.awt.event.*;
  8. importjava.util.*;
  9. publicclassTongXunLu{
  10. Map<String,String>map=newHashMap<String,String>();
  11. TextFieldt1=newTextField(10);
  12. TextFieldt2=newTextField(10);
  13. TextFieldt3=newTextField(10);
  14. TextFieldt4=newTextField(10);
  15. TextAreata=newTextArea("",5,3,1);
  16. publicTongXunLu(){
  17. Framef=newFrame("电话本1.0(EKOI)");
  18. //f.setSize(600,400);
  19. f.setVisible(true);
  20. f.setLayout(newGridLayout(3,0));
  21. Panelp1=newPanel();
  22. Panelp2=newPanel();
  23. p1.setLayout(newFlowLayout());
  24. p2.setLayout(newFlowLayout());
  25. ta.setEditable(false);//*********
  26. Labell1=newLabel("name");
  27. Labell2=newLabel("number");
  28. Labell3=newLabel("name");
  29. Labell4=newLabel("number");
  30. Buttonb1=newButton("add");
  31. Buttonb2=newButton("search");
  32. Buttonb3=newButton("allitem");
  33. b1.addActionListener(newB1Lister());
  34. b2.addActionListener(newB2Lister());
  35. b3.addActionListener(newB3Lister());
  36. p1.add(l1);
  37. p1.add(t1);
  38. p1.add(l2);
  39. p1.add(t2);
  40. p1.add(b1);
  41. f.add(p1);
  42. p2.add(l3);
  43. p2.add(t3);
  44. p2.add(b2);
  45. p2.add(b3);
  46. f.add(p2);
  47. f.add(ta);
  48. f.setResizable(false);
  49. f.pack();
  50. f.addWindowListener(newWindowAdapter()
  51. {
  52. publicvoidwindowClosing(WindowEvente)
  53. {
  54. System.exit(-1);
  55. }
  56. }
  57. );
  58. }
  59. publicstaticvoidmain(String[]args)throwsException
  60. {
  61. newTongXunLu();
  62. }
  63. classB1ListerimplementsActionListener
  64. {
  65. publicvoidactionPerformed(ActionEvente)
  66. {
  67. Stringstr=t1.getText();
  68. Stringnum=t2.getText();
  69. t1.setText("");
  70. t2.setText("");
  71. map.put(str,num);
  72. ta.setText("");
  73. ta.setText("insertok");
  74. }
  75. }
  76. classB2ListerimplementsActionListener
  77. {
  78. publicvoidactionPerformed(ActionEvente)
  79. {
  80. Stringstr=null;
  81. Stringnum;
  82. str=t3.getText();
  83. t3.setText("");
  84. num=map.get(str);
  85. ta.setText("");
  86. if(num==null)
  87. ta.setText("对不起,没有记录");
  88. else
  89. ta.setText("name:"+str+"\nnum:"+num);
  90. }
  91. }
  92. classB3ListerimplementsActionListener
  93. {
  94. publicvoidactionPerformed(ActionEvente)
  95. {
  96. //Collection<String>c=map.values();
  97. ta.setText("");
  98. Stringstr=map.toString();
  99. Stringstr1=str.substring(1,str.length()-1);
  100. String[]end=str1.split(",");
  101. for(inti=0;i<end.length;i++)
  102. {
  103. String[]t=end[i].split("=");
  104. ta.append("name:"+t[0]+"number:"+t[1]+"\n");
  105. //System.out.println("name:"+t[0]+"number:"+t[1]);
  106. }
  107. }
  108. }
  109. classDis
  110. {
  111. Stringname;
  112. intnum;
  113. }
  114. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值