2012-08-08 3 views
0

Netbeans IDE 7.1을 사용하여 Java 프로젝트를 작성하려고합니다.NetBeans Java 프로젝트에서 GUI 창에 오류가 표시되지 않음

내가 만든 GUI 창을 어떻게 든 보거나 볼 수 없습니다.

친절하게 조언하십시오. 내 수업에서

:

package rmiSimpleCalc; 

public class RMISimpleCalculatorMain { 

    public static void main(String[] args) { 
     MainCalculator calc = new MainCalculator(); 
     calc.setVisible(true); 
    } 
} 

MainCalculator 내가 실행하고자하는 GUI 창입니다. 그것은 어떻게 든 표시하지 않을 것이다.

package rmiSimpleCalc; 

import java.rmi.*; 

public class MainCalculator extends javax.swing.JPanel { 

    public MainCalculator() { 
     initComponents(); 
     ComboBoxOperator.addItem("+"); 
     ComboBoxOperator.addItem("-"); 
     ComboBoxOperator.addItem("/"); 
     ComboBoxOperator.addItem("*");    
    } 

    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">       
    private void initComponents() { 

     txtFirstDigit = new javax.swing.JTextField(); 
     txtSecondDigit = new javax.swing.JTextField(); 
     btnCalculate = new javax.swing.JButton(); 
     lblFirstDigit = new javax.swing.JLabel(); 
     lblSecondDigit = new javax.swing.JLabel(); 
     ComboBoxOperator = new javax.swing.JComboBox(); 
     lblOperator = new javax.swing.JLabel(); 
     lblResult = new javax.swing.JLabel(); 
     lblHeader = new javax.swing.JLabel(); 
     btnConfigureServer = new javax.swing.JButton(); 
     txtResult = new javax.swing.JTextField(); 

     btnCalculate.setText("Calculate"); 
     btnCalculate.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       btnCalculateActionPerformed(evt); 
      } 
     }); 

     lblFirstDigit.setText("First Digit"); 

     lblSecondDigit.setText("Second Digit"); 

     ComboBoxOperator.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); 

     lblOperator.setText("Operator"); 

     lblResult.setText("Result"); 

     lblHeader.setText("RMI Simple Calculator"); 

     btnConfigureServer.setText("Configure Server"); 
     btnConfigureServer.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       btnConfigureServerActionPerformed(evt); 
      } 
     }); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 
     this.setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addComponent(lblFirstDigit, javax.swing.GroupLayout.Alignment.TRAILING) 
        .addComponent(lblSecondDigit, javax.swing.GroupLayout.Alignment.TRAILING) 
        .addComponent(lblOperator, javax.swing.GroupLayout.Alignment.TRAILING) 
        .addComponent(lblResult, javax.swing.GroupLayout.Alignment.TRAILING)) 
       .addGap(18, 18, 18) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addComponent(lblHeader) 
        .addGroup(layout.createSequentialGroup() 
         .addComponent(ComboBoxOperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addGap(18, 18, 18) 
         .addComponent(btnCalculate)) 
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
         .addComponent(txtSecondDigit) 
         .addComponent(txtFirstDigit, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)) 
        .addGroup(layout.createSequentialGroup() 
         .addComponent(txtResult, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) 
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
         .addComponent(btnConfigureServer))) 
       .addContainerGap()) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addGap(12, 12, 12) 
       .addComponent(lblHeader) 
       .addGap(18, 18, 18) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(txtFirstDigit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(lblFirstDigit)) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(txtSecondDigit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(lblSecondDigit)) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(ComboBoxOperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(lblOperator) 
        .addComponent(btnCalculate)) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(lblResult) 
        .addComponent(txtResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
       .addComponent(btnConfigureServer) 
       .addContainerGap(24, Short.MAX_VALUE)) 
     ); 
    }      

    private void btnConfigureServerActionPerformed(java.awt.event.ActionEvent evt) {             

    }             

    private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {            
     double firstdigit; 
     double seconddigit; 
     String operator; 

     firstdigit = Double.valueOf(txtFirstDigit.getText()); 

     seconddigit = Double.valueOf(txtSecondDigit.getText()); 

     operator = ComboBoxOperator.getSelectedItem().toString(); 

     try 
     { 
      CoreInterface coreobj = (CoreInterface) Naming.lookup("localhost/Core"); 
      double result = (coreobj.calc(firstdigit,seconddigit,operator)); 
      txtResult.setText(Double.toString(result)); 
     } 

     catch(Exception e) 
     { 
      txtResult.setText("e"); 
     } 
    }            

    private javax.swing.JComboBox ComboBoxOperator; 
    private javax.swing.JButton btnCalculate; 
    private javax.swing.JButton btnConfigureServer; 
    private javax.swing.JLabel lblFirstDigit; 
    private javax.swing.JLabel lblHeader; 
    private javax.swing.JLabel lblOperator; 
    private javax.swing.JLabel lblResult; 
    private javax.swing.JLabel lblSecondDigit; 
    private javax.swing.JTextField txtFirstDigit; 
    private javax.swing.JTextField txtResult; 
    private javax.swing.JTextField txtSecondDigit; 
    // End of variables declaration     
} 

어떤 조언을 감사 :

힘든 내 콘솔 NO 오류 메시지가 .. 여기

MainCalculator 코드가된다.

+1

MainCalculator 클래스의 코드가 유용 할 것입니다. – ChadNC

+0

'RMISimpleCalculatorMain'이 주 ​​클래스로 정의되어 있는지 확인하십시오. – EyalAr

+0

확실히 나는 그것을 메인 클래스로 정의했다. ... – rofans91

답변

2

MainCalculator 클래스는 JPanel이다. JPanel은 이와 같이 표시 할 수 없으며 Window의 일부 여야합니다. 그것을 JFrame에 추가하고 JFramesetVisible(true)으로 전화하십시오.

또한 npinti의 조언은 매우 좋습니다. EDT 스레드에서 GUI 관련 코드를 실행하십시오.

1

문제는이 섹션의 가능성이 높습니다 :

public static void main(String[] args) { 
     MainCalculator calc = new MainCalculator(); 
     calc.setVisible(true); 
    } 

당신은 이벤트 디스패처 스레드 (EDT) 내에서 어떤 GUI 관련 작업을 확인해야합니다. 그래서 같은

시도 뭔가 :

public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() 
     { 
      @Override 
      public void run() 
      { 
       MainCalculator calc = new MainCalculator(); 
       calc.setVisible(true); 
      } 
     }); 
    } 
+0

나는 그것을 시도했지만 에러가 발생했다. 어떤 생각 일까? – rofans91

+0

@rofansmanao : 오류가 무엇인가요? 내 코드에 오타가 있었어. 끝에'.start() '를 추가해야 할 수도 있습니다. – npinti

+0

java.lang.Runnable은 추상 클래스이며, 추상 메소드를 구현할 수 없습니다. – rofans91