天天看點

為什麼這個檔案用JAVAC和JAVA可以運作,但是用NETBEANS運作不了.....

java 代碼

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

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編譯就會出現如下錯誤: