Java 2个JButtons 2个GUI

Java 2个JButtons 2个GUI,java,swing,user-interface,netbeans,jbutton,Java,Swing,User Interface,Netbeans,Jbutton,大家好,我想知道为什么我在一个叫colin的gui上的两个JButton不能正常工作 当我点击Ok按钮调用名为userino_frame的gui时,出现Ok,但当我点击clear按钮打开motor_frame gui时,gui在线程“AWT-EventQueue-0”java.lang.UnsupportedOperationException:尚未实现消息中给出异常 我尝试了几种方法来改变这一点,但都没有用,因为我只想在按下按钮时打开个性化gui import javax.swing.JBut

大家好,我想知道为什么我在一个叫colin的gui上的两个JButton不能正常工作 当我点击Ok按钮调用名为userino_frame的gui时,出现Ok,但当我点击clear按钮打开motor_frame gui时,gui在线程“AWT-EventQueue-0”java.lang.UnsupportedOperationException:尚未实现消息中给出异常 我尝试了几种方法来改变这一点,但都没有用,因为我只想在按下按钮时打开个性化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
}
import javax.swing.JButton;
公共类colin扩展了javax.swing.JFrame{
私有静态类e{
私有静态对象getSource(){
抛出新的UnsupportedOperationException(“尚未实现”);
}
公共服务电子化(){
}
}
私人静态级新车{
公共新车{
}
}
私有对象新车框架;
专用静态类新车\车架\车架{
公共新车车架车架(){
}
}
/**
*创建新表单colin
*/
公共科林(){
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
// 
私有组件(){
Ok=newjava.awt.Button();
motor=newjava.awt.Button();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE\u ON\u CLOSE);
好的。设置标签(“按钮1”);
Ok.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作(evt);
}
});
电机设置标签(“按钮1”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的机动车辆(evt);
}
});
javax.swing.GroupLayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(布局);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(95,95,95).addComponent(确定,javax.swing.GroupLayout.PREFERRED_大小,javax.swing.GroupLayout.DEFAULT_大小,javax.swing.GroupLayout.PREFERRED_大小).addGap(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.PREFERRED_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(122,122));
包装();
}// 
private void OkActionPerformed(java.awt.event.ActionEvent evt){
//如果(evt.getSource()==Ok){
userino_frame s=新的userino_frame();
s、 setVisible(真);
}
private void motorActionPerformed(java.awt.event.ActionEvent evt){
//if(evt.getSource()=清除){
电机机架v=新电机机架();
v、 setVisible(真);
}
/**
*@param指定命令行参数
*/
公共静态void main(字符串参数[]){
/*
*设置Nimbus的外观和感觉
*/
//
/*
*如果Nimbus(在JavaSE6中引入)不可用,请使用
*默认外观。有关详细信息,请参阅
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
试一试{
for(javax.swing.UIManager.LookAndFeelInfo:javax.swing.UIManager.getInstalledLookAndFeels()){
if(“Nimbus”.equals(info.getName())){
setLookAndFeel(info.getClassName());
打破
}
}
}捕获(ClassNotFoundException ex){
getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}catch(实例化异常){
getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}捕获(非法访问例外){
getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}catch(javax.swing.UnsupportedLookAndFeelException ex){
getLogger(colin.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}
//
/*
*创建并显示表单
*/
invokeLater(new Runnable()){
公开募捐{
new colin().setVisible(true);
}
});
}
//变量声明-不修改
private java.awt.Button Ok;
专用java.awt.Button电机;
//变量结束声明
}

您似乎忘记了实现该功能:

    private static Object getSource() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
您必须用实际逻辑替换
throw

  • 使用而不是创建大量

  • userino\u frame s=new userino\u frame();
    motor\u frame v=new motor\u frame();
    的内容放入卡中

  • 从仅在这两张卡之间切换视图


  • 我想这没关系……这个方法永远不会被调用。它可能会被调用