2012-08-09 85 views
1

大家好,我想知道为什么我的2个gui上的jbuttons叫colin,我在这里将无法正常工作 当我点击确定按钮调用GUI命名为userino_frame这会出现好,但当我点击清除按钮来调出motor_frame gui gui给我例外线程“AWT-EventQueue-0”java.lang.UnsupportedOperationException:尚未实现的消息 我已经尝试了几种方法来改变这一点,但无济于事,因为我想做的事情被调出时,按下按钮2 JButtons 2 GUI

import javax.swing.JButton; 

public class colin extends javax.swing.JFrame { 

    private static class e { 
     private static Object getSource() { 
      throw new UnsupportedOperationException("Not yet implemented"); 
     } 
     public e() { 
     } 
    } 

    private static class newcar { 
     public newcar() { 
     } 
    } 
    private Object newcar_frame; 

    private static class newcar_frame_frame { 
     public newcar_frame_frame() { 
     } 
    } 

    /** 
    * Creates new form colin 
    */ 
    public colin() { 
     initComponents(); 
    } 

    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> 
    private void initComponents() { 
     Ok = new java.awt.Button(); 
     motor = new java.awt.Button(); 
     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 
     Ok.setLabel("button1"); 
     Ok.addActionListener(new java.awt.event.ActionListener() { 

      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       OkActionPerformed(evt); 
      } 
     }); 
     motor.setLabel("button1"); 
     motor.addActionListener(new java.awt.event.ActionListener() { 

      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       motorActionPerformed(evt); 
      } 
     }); 
     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
       layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(95, 95, 95).addComponent(Ok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(80, 80, 80).addComponent(motor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(111, Short.MAX_VALUE))); 
     layout.setVerticalGroup(
       layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(154, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(motor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(Ok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(122, 122, 122))); 

     pack(); 
    }// </editor-fold> 

    private void OkActionPerformed(java.awt.event.ActionEvent evt) { 
     //if(evt.getSource()==Ok){ 
     userino_frame s = new userino_frame(); 
     s.setVisible(true); 
    } 

    private void motorActionPerformed(java.awt.event.ActionEvent evt) { 
     //if(evt.getSource()==Clear){ 
     motor_frame v = new motor_frame(); 
     v.setVisible(true); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String args[]) { 
     /* 
     * Set the Nimbus look and feel 
     */ 
     //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
     /* 
     * If Nimbus (introduced in Java SE 6) is not available, stay with the 
     * default look and feel. For details see 
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */ 
     try { 
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
       if ("Nimbus".equals(info.getName())) { 
        javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
     } catch (ClassNotFoundException ex) { 
      java.util.logging.Logger.getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } 
     //</editor-fold> 

     /* 
     * Create and display the form 
     */ 
     java.awt.EventQueue.invokeLater(new Runnable() { 

      public void run() { 
       new colin().setVisible(true); 
      } 
     }); 
    } 
    // Variables declaration - do not modify 
    private java.awt.Button Ok; 
    private java.awt.Button motor; 
    // End of variables declaration 
} 
+1

你还应该发布stacktrace的例外。这使得调试更容易。 – Alderath 2012-08-09 13:35:26

+1

请学习[Java命名约定](http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html)并严格遵守它们:-) AFAICS,您将初始化一个新的' JFrame的每个按钮点击,你不应该这样做,而是简单地检查实例是否已经显示,并提供一个窗口,如果它不是,虽然mKorbel的答案太棒了话题,从不使用两个'JFrame'。否则这里是一个[示例](http://stackoverflow.com/a/9443609/1057230)来说明我在说什么:-) – 2012-08-09 16:40:25

回答

0

看来你忘了实现该功能的indiviual GUI:

private static Object getSource() { 
     throw new UnsupportedOperationException("Not yet implemented"); 
    } 

您必须用实际逻辑替换throw行。而不是

+0

这应该不重要,我认为...该方法从来没有被称为。它也可以被删除。问题肯定是非常相似的东西,虽然。 – Alderath 2012-08-09 13:27:04

+0

谢谢你们,我到那里最后很受欢迎 – user1571125 2012-08-09 20:42:00