1

GUI を完成させようとしていたとき、いたるところでエラーが発生していることに気付きましたが、それ以前はすべて問題なく動作していました。別のパネルを呼び出そうとすると、「シンボルが見つかりません」というエラーが表示されます。

this.setContentPane(servicios);

とエラー"Class, interface or enum expected" on object methods and some "}":

text.setText(text.getText()+"\nInternet 20 mbps = $1199");

私は間違っているように見えるものを見つけることができません。

これはコンソールからのエラーです: Exception in thread "main" java.lang.VerifyError: Constructor must call super() or this() before return in method sistema.Principal.()V at offset 0 at sistema.Sistema.main (Sistema.java:18) Java 結果: 1

コードは次のとおりです。

Jframe:

 public class Principal extends javax.swing.JFrame {


     float total, x1=0, x2=0, x3=0;

         total=total+x1+x2+x3;
     /**
      * Creates new form Principal
      */

     public Principal() {
         initComponents();
     }

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

         // TODO add your handling code here:
         this.setContentPane(servicios);
         validate();

     }                                  

     private void b2ActionPerformed(java.awt.event.ActionEvent evt) {                                   
         // TODO add your handling code here:
         this.setContentPane(productos);
         validate();
     }                                  

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

         // TODO add your handling code here:
         if(c1.isSelected());
         {
             x1=199;
             text.setText(text.getText()+"\nInternet 2 mbps = $199");
         }
         if(c2.isSelected());
         {
             x1=399;
             text.setText(text.getText()+"\nInternet 5 mbps = $399");
         }
         if(c3.isSelected());
         {
             x1=699;
             text.setText(text.getText()+"\nInternet 10 mbps = $699");
         }
         if(c4.isSelected());
         {
             x1=1199;
             text.setText(text.getText()+"\nInternet 20 mbps = $1199");
         }

         else{
              ms1.setText("Para agregar al carrito\nselecciona una opcion");
             }

     }                                              

     private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         if(c5.isSelected());
         {
             x2=99;
             text.setText(text.getText()+"\n100 llamadas nacionales = $99");
         }
         if(c6.isSelected());
         {
             x2=299;
             text.setText(text.getText()+"\nLlamadas nacionales ilimitadas = $299");
         }
         if(c7.isSelected());
         {
             x2=359;
             text.setText(text.getText()+"\n50 minutos larga distancia = $359");
         }
        if(c8.isSelected());
         {
             x2=999;
             text.setText(text.getText()+"\nTelefonía ilimitada = $999");
             }

         else{
                 ms2.setText("Para agregar a carrito\nselecciona una opcion");
      }
     }                                        

     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         System.exit(WIDTH);
     }                                        

     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         setContentPane(jPanel1);
         revalidate();
     }                                        

     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         t1.setText("Total = $"+total);
         setContentPane(carrito);
         revalidate();
     }                                        

     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         System.exit(WIDTH);
     }                                        

     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         setContentPane(jPanel1);
         revalidate();
     }                                        

     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         setContentPane(salida);
         revalidate();
     }                                        

     private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         x3=x3+5670;
         text.setText(text.getText()+"\nComputadora DELL = $5,670");
     }                                        

     private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         // TODO add your handling code here:
         x3=x3+8450;
         text.setText(text.getText()+"\nLaptop DELL = $8,450");
     }                                        

     private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         x3=x3+11780;
         text.setText(text.getText()+"\nLaptop SONY = $11,870");
     }                                         

     private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         x3=x3+1200;
     text.setText(text.getText()+"\nMódem 2WIRE  = $1,200");
     }                                         

     private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         x3=x3+5700;
         text.setText(text.getText()+"\nTelevision LCD = $5,700");
     }                                         

     private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         x3=x3+4500;
         text.setText(text.getText()+"\nConsola Xbox 360 = $4,500");
     }                                         

     private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         System.exit(WIDTH);
     }                                         

     private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         setContentPane(jPanel1);
         revalidate();
     }                                         

     private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         // TODO add your handling code here:
         t1.setText("Total = $"+total);
         setContentPane(carrito);
         revalidate();
     }                                         


     /**
      * @param args the command line arguments
      */
     public static void main(String args[]) {

  java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                 new Principal().setVisible(true);
             }
         });
     }

     private javax.swing.JButton b1;
     private javax.swing.JButton b2;
     private javax.swing.ButtonGroup buttonGroup1;
     private javax.swing.ButtonGroup buttonGroup2;
     private javax.swing.JCheckBox c1;
     private javax.swing.JCheckBox c2;
     private javax.swing.JCheckBox c3;
     private javax.swing.JCheckBox c4;
     private javax.swing.JCheckBox c5;
     private javax.swing.JCheckBox c6;
     private javax.swing.JCheckBox c7;
     private javax.swing.JCheckBox c8;
     private javax.swing.JPanel carrito;
     private javax.swing.JLabel icon;
     private javax.swing.JButton jButton1;
     private javax.swing.JButton jButton10;
     private javax.swing.JButton jButton11;
     private javax.swing.JButton jButton12;
     private javax.swing.JButton jButton13;
     private javax.swing.JButton jButton14;
     private javax.swing.JButton jButton15;
     private javax.swing.JButton jButton16;
     private javax.swing.JButton jButton2;
     private javax.swing.JButton jButton3;
     private javax.swing.JButton jButton4;
     private javax.swing.JButton jButton5;
     private javax.swing.JButton jButton6;
     private javax.swing.JButton jButton7;
     private javax.swing.JButton jButton8;
     private javax.swing.JButton jButton9;
     private javax.swing.JLabel jLabel1;
     private javax.swing.JLabel jLabel10;
     private javax.swing.JLabel jLabel11;
     private javax.swing.JLabel jLabel2;
     private javax.swing.JLabel jLabel3;
     private javax.swing.JLabel jLabel5;
     private javax.swing.JLabel jLabel6;
     private javax.swing.JLabel jLabel7;
     private javax.swing.JLabel jLabel8;
     private javax.swing.JLabel jLabel9;
     private javax.swing.JPanel jPanel1;
     private javax.swing.JPanel jPanel2;
     private javax.swing.JPanel jPanel3;
     private javax.swing.JScrollPane jScrollPane1;
     private javax.swing.JScrollPane jScrollPane2;
     private javax.swing.JScrollPane jScrollPane3;
     private javax.swing.JScrollPane jScrollPane4;
     private javax.swing.JScrollPane jScrollPane5;
     private javax.swing.JScrollPane jScrollPane6;
     private javax.swing.JScrollPane jScrollPane7;
     private javax.swing.JScrollPane jScrollPane8;
     private javax.swing.JTextArea jTextArea1;
     private javax.swing.JTextArea jTextArea2;
     private javax.swing.JTextArea jTextArea3;
     private javax.swing.JTextArea jTextArea4;
     private javax.swing.JTextArea jTextArea5;
     private javax.swing.JTextArea jTextArea6;
     private javax.swing.JTextArea jTextArea7;
     private javax.swing.JTextField jTextField1;
     private javax.swing.JTextField jTextField2;
     private javax.swing.JTextField jTextField3;
     private javax.swing.JToggleButton jToggleButton1;
     private javax.swing.JLabel jlabel3;
     private javax.swing.JLabel l1;
     private javax.swing.JLabel l2;
     private javax.swing.JLabel ms1;
     private javax.swing.JLabel ms2;
     private javax.swing.JLabel p1;
     private javax.swing.JLabel p2;
     private javax.swing.JLabel p3;
     private javax.swing.JLabel p4;
     private javax.swing.JLabel p5;
     private javax.swing.JLabel p6;
     private javax.swing.JPanel productos;
     private javax.swing.JPanel salida;
     private javax.swing.JPanel servicios;
     private javax.swing.JTextArea text;
     private javax.swing.JLabel ts1;

メインクラス:

package sistema;

/**  *  * @author David  */ public class Sistema {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Principal a =  new Principal();
        a.setVisible(true);
        a.setLocationRelativeTo(null);

    }
}
4

1 に答える 1

2

エラーが多い!!

まず第一に、なぜsemicolon(;)すべての if ステートメントの後にあるのですか。それらを削除します。

}クラスの最後にクロージングがありません。

メソッドはどこinitComponents()ですか??

編集: GUI エディターを使用して GUI を作成したようです。その場合、initComponents() が表示されない場合があります。

をどこで使用していますかprivate javax.swing.JLabel ts1;。それはあるはずprivate javax.swing.JTextArea t1;ですか?

于 2012-11-28T18:08:33.750 に答える