首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

为啥这个文件用JAVAC和JAVA可以运行,但是用NETBEANS运行不了.

2012-10-30 
为什么这个文件用JAVAC和JAVA可以运行,但是用NETBEANS运行不了.....import?java.awt.* ??import?java.awt

为什么这个文件用JAVAC和JAVA可以运行,但是用NETBEANS运行不了.....

  1. import?java.awt.*; ??
  2. import?java.awt.event.*; ??
  3. import?javax.swing.*; ??
  4. public?class?Calculator?{ ??
  5. ???? ??
  6. ????/** ?
  7. ?????*?Creates?a?new?instance?of?Calculator ?
  8. ?????*?@param?args? ?
  9. ?????*/??
  10. ????public?static?void?main(String[]?args)?{ ??
  11. ????????CalFrame?frame=new?CalFrame(); ??
  12. ????????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ??
  13. ????????frame.show(); ??
  14. ????} ??
  15. ???? ??
  16. ???? ??
  17. } ??
  18. class?CalFrame?extends?JFrame{ ??
  19. ????public?CalFrame(){ ??
  20. ????????setTitle("龙斌原创计算器程序"); ??
  21. ????????setSize(300,300); ??
  22. ????????Container?contentPane=getContentPane(); ??
  23. ????????CalPanel?panel=new?CalPanel(); ??
  24. ????????contentPane.add(panel); ??
  25. ????????pack(); ??
  26. ???????? ??
  27. ????} ??
  28. } ??
  29. class?CalPanel?extends?JPanel{ ??
  30. ????public?CalPanel(){ ??
  31. ????????setLayout(new?BorderLayout()); ??
  32. ????????result=0; ??
  33. ????????lastCommand="="; ??
  34. ????????start=true; ??
  35. ????????display=new?JLabel("0"); ??
  36. ????????add(display,BorderLayout.NORTH); ??
  37. ????????ActionListener?insert=new?InsertAction(); ??
  38. ????????ActionListener?command=new?CommandAction(); ??
  39. ???????? ??
  40. ????????panel=new?JPanel(); ??
  41. ????????panel.setLayout(new?GridLayout(4,4)); ??
  42. ????????addButton("7",insert); ??
  43. ????????addButton("8",insert); ??
  44. ????????addButton("9",insert); ??
  45. ????????addButton("/",command); ??
  46. ???????? ??
  47. ????????addButton("4",insert); ??
  48. ????????addButton("5",insert); ??
  49. ????????addButton("6",insert); ??
  50. ????????addButton("*",command); ??
  51. ???????? ??
  52. ????????addButton("1",insert); ??
  53. ????????addButton("2",insert); ??
  54. ????????addButton("3",insert); ??
  55. ????????addButton("-",command); ??
  56. ???? ??
  57. ????????addButton("0",insert); ??
  58. ????????addButton(".",insert); ??
  59. ????????addButton("=",insert); ??
  60. ????????addButton("+",command); ??
  61. ???????? ??
  62. ????????add(panel,BorderLayout.CENTER); ??
  63. ????} ??
  64. ???? ??
  65. ????private?void?addButton(String?label,ActionListener?listener){ ??
  66. ????????JButton?button=new?JButton(label); ??
  67. ????????button.addActionListener(listener); ??
  68. ????????panel.add(button); ??
  69. ????} ??
  70. ???? ??
  71. ????private?class?InsertAction?implements?ActionListener{ ??
  72. ????????public?void?actionPerformed(ActionEvent?event){ ??
  73. ????????????String?input=event.getActionCommand(); ??
  74. ????????????if(start){ ??
  75. ????????????????display.setText(""); ??
  76. ????????????????start=false; ??
  77. ????????????} ??
  78. ????????????display.setText(display.getText()+input); ??
  79. ????????} ??
  80. ????} ??
  81. ????private?class?CommandAction?implements?ActionListener{ ??
  82. ????????public?void?actionPerformed(ActionEvent?evt){ ??
  83. ???????????String?command=evt.getActionCommand();? ??
  84. ???????????if(start){ ??
  85. ???????????????if(command.equals("-")){ ??
  86. ???????????????????display.setText(command); ??
  87. ???????????????????start=false; ??
  88. ???????????????} ??
  89. ???????????????else?lastCommand=command; ??
  90. ???????????} ??
  91. ???????????else{ ??
  92. ???????????????calculate(Double.parseDouble(display.getText())); ??
  93. ???????????????lastCommand=command; ??
  94. ???????????????start=true; ??
  95. ???????????} ??
  96. ????????} ??
  97. ????} ??
  98. ??
  99. ?public?void?calculate(double?x){ ??
  100. ?????if(lastCommand.equals("+"))?result+=x; ??
  101. ?????else?if(lastCommand.equals("-"))?result-=x; ??
  102. ?????else?if(lastCommand.equals("*"))?result*=x; ??
  103. ?????else?if(lastCommand.equals("/"))?result/=x; ??
  104. ?????else?if(lastCommand.equals("="))?result=x; ??
  105. ?????display.setText(""+result); ??
  106. ?} ??
  107. ?private?JLabel?display; ??
  108. ?private?JPanel?panel; ??
  109. ?private?double?result; ??
  110. ?private?String?lastCommand; ??
  111. ?private?boolean?start; ??
  112. ???? ??
  113. } ??
  114. ??

?

init:
deps-jar:
compile:
compile-test:
.F
Time: 0
There was 1 failure:
1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError: No tests found in Calculator

FAILURES!!!
Tests run: 1,? Failures: 1,? Errors: 0

debug-test:
生成成功(总时间:1 秒)

使用NETBEANS编译就会出现如下错误:

热点排行