Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java清除netbeans中的jFrame_Java_Swing_Netbeans_Jframe - Fatal编程技术网

Java清除netbeans中的jFrame

Java清除netbeans中的jFrame,java,swing,netbeans,jframe,Java,Swing,Netbeans,Jframe,我目前正在创建一个游戏,遇到了一个大问题:如何清除jFrames然后添加新内容?我已经看到了所有其他问题和答案,但它们不起作用。这是我的代码。我想我的单人按钮,以清除屏幕,然后添加新的内容 * * @author Kyle */ public class mainscreen extends javax.swing.JFrame { /** * Creates new form main screen */ public mainscreen() {

我目前正在创建一个游戏,遇到了一个大问题:如何清除jFrames然后添加新内容?我已经看到了所有其他问题和答案,但它们不起作用。这是我的代码。我想我的单人按钮,以清除屏幕,然后添加新的内容

 *
 * @author Kyle
 */
public class mainscreen extends javax.swing.JFrame {

    /**
     * Creates new form main screen
     */
    public mainscreen() {
        setTitle("My, World");

        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() {

        jPanel1 = new javax.swing.JPanel();
        jcredit2 = new javax.swing.JLabel();
        jcredit1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jcredit3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));

        jcredit2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 14)); // NOI18N
        jcredit2.setForeground(new java.awt.Color(255, 255, 255));

        jcredit1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 14)); // NOI18N
        jcredit1.setForeground(new java.awt.Color(255, 255, 255));

        jButton1.setBackground(new java.awt.Color(0, 0, 0));
        jButton1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24)); // NOI18N
        jButton1.setForeground(new java.awt.Color(255, 255, 255));
        jButton1.setText("Singleplayer");
        jButton1.setOpaque(true);
        jButton1.setBorder(null);
        jButton1.setContentAreaFilled(false);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mouseCsingleplayer(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                mouseentersingleplayer(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                mouseexitsingleplayer(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(0, 0, 0));
        jButton2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24)); // NOI18N
        jButton2.setForeground(new java.awt.Color(255, 255, 255));
        jButton2.setText("Multiplayer");
        jButton2.setBorder(null);
        jButton2.setName(""); // NOI18N
        jButton2.setContentAreaFilled(false);
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                mouseentermultiplayer(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                mouseexitmultiplayer(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(0, 0, 0));
        jButton3.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24)); // NOI18N
        jButton3.setForeground(new java.awt.Color(255, 255, 255));
        jButton3.setText("Options");
        jButton3.setBorder(null);
        jButton3.setOpaque(false);

        jButton3.setContentAreaFilled(false);
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                mousenteroptions(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                Mouseexitoptions(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 70)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("My, World");

        jLabel2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));

        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                mouseclickfrog(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                mouseexitfrog(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24)); // NOI18N
        jButton4.setForeground(new java.awt.Color(255, 255, 255));
        jButton4.setText("Credits");
        jButton4.setBorder(null);
        jButton4.setOpaque(false);
        jButton3.setOpaque(false);

        jButton4.setContentAreaFilled(false);
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Jbutton4CLicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                Jbutton4hover1(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton4Mouseexitoptions(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 187, Short.MAX_VALUE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jcredit1, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                            .addComponent(jcredit2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcredit3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(22, 22, 22))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jcredit1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcredit2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcredit3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(54, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

    private void mouseentersingleplayer(java.awt.event.MouseEvent evt) {                                        
 jButton1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 27));
 jLabel2.setText(" Create a new world or load a old one!");
 jButton1.setText("<Singleplayer>");

    }                                       

    private void mouseexitsingleplayer(java.awt.event.MouseEvent evt) {                                       
 jButton1.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 25));
  jLabel2.setText("");
  jButton1.setText("Singleplayer");
    }                                      

    private void mouseentermultiplayer(java.awt.event.MouseEvent evt) {                                       
 jButton2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 27));
  jLabel2.setText(" Play LAN or online with friends!");
  jButton2.setText("<Multiplayer>");
    }                                      

    private void mouseexitmultiplayer(java.awt.event.MouseEvent evt) {                                      
 jButton2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24));
  jLabel2.setText("");
  jButton2.setText("Multiplayer");
    }                                     

    private void mousenteroptions(java.awt.event.MouseEvent evt) {                                  
 jButton3.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 27));
  jLabel2.setText(" Configure your life!");
  jButton3.setText("<Options>");
    }                                 

    private void Mouseexitoptions(java.awt.event.MouseEvent evt) {                                  
 jButton3.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24));
  jLabel2.setText("");
  jButton3.setText("Options");

    }                                 

    private void mouseclickfrog(java.awt.event.MouseEvent evt) {                                
  jLabel2.setText("Copyright, Applacation Amphibian 2013");
    }                               

    private void mouseexitfrog(java.awt.event.MouseEvent evt) {                               
jLabel2.setText("");
    }                              

    private void Jbutton4CLicked(java.awt.event.MouseEvent evt) {                                 
jButton4.setText("<credits>");

    }                                

    private void Jbutton4hover1(java.awt.event.MouseEvent evt) {                                
jButton4.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 27));
jcredit1.setText("Head of project: Kyle Jackson");
jcredit2.setText("Graphics: Lachlan Hatfeild");
jButton4.setText("<Credits>");

    }                               

    private void jButton4Mouseexitoptions(java.awt.event.MouseEvent evt) {                                          
jButton4.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 24));
jcredit1.setText("");
jcredit2.setText("");
jButton4.setText("Credits");
    }                                         

    private void mouseCsingleplayer(java.awt.event.MouseEvent evt) {                                    

    }                                   

    /**
     * @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(mainscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(mainscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(mainscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(mainscreen.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 mainscreen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel jcredit1;
    private javax.swing.JLabel jcredit2;
    private javax.swing.JLabel jcredit3;
    // End of variables declaration                   

    private void clear() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
*
*@作者凯尔
*/
公共类主屏幕扩展了javax.swing.JFrame{
/**
*创建新窗体主屏幕
*/
公共主屏幕(){
片名(“我的,世界”);
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//                           
私有组件(){
jPanel1=newjavax.swing.JPanel();
jcredit2=newjavax.swing.JLabel();
jcredit1=newjavax.swing.JLabel();
jButton1=newjavax.swing.JButton();
jButton2=newjavax.swing.JButton();
jButton3=newjavax.swing.JButton();
jLabel1=newjavax.swing.JLabel();
jLabel2=newjavax.swing.JLabel();
jLabel3=newjavax.swing.JLabel();
jButton4=newjavax.swing.JButton();
jcredit3=newjavax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(新java.awt.Color(0,0,0));
set前台(新java.awt.Color(255、255、255));
jcredit2.setFont(新java.awt.Font(“Arial圆角MT Bold”,0,14));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jcredit1.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,14));//NOI18N
setForeground(新java.awt.Color(255、255、255));
setBackground(新java.awt.Color(0,0,0));
jButton1.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,24));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jButton1.setText(“Singleplayer”);
jButton1.setOpaque(true);
jButton1.setboorder(null);
jButton1.setContentAreaFilled(false);
jButton1.addMouseListener(新java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent evt){
mouseCsingleplayer(evt);
}
public void mouseenterned(java.awt.event.MouseEvent evt){
mouseentersingleplayer(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt){
mouseexitsingleplayer(evt);
}
});
setBackground(新java.awt.Color(0,0,0));
jButton2.setFont(新java.awt.Font(“Arial圆角MT Bold”,0,24));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jButton2.setText(“多人游戏”);
jButton2.setboorder(null);
jButton2.setName(“”;//NOI18N
jButton2.setContentAreaFilled(false);
jButton2.addMouseListener(新java.awt.event.MouseAdapter(){
public void mouseenterned(java.awt.event.MouseEvent evt){
mouseentermultiplayer(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt){
Mouseexit多人游戏(evt);
}
});
setBackground(新java.awt.Color(0,0,0));
jButton3.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,24));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jButton3.setText(“选项”);
jButton3.setboorder(null);
jButton3.setOpaque(false);
jButton3.setContentAreaFilled(false);
addMouseListener(新java.awt.event.MouseAdapter(){
public void mouseenterned(java.awt.event.MouseEvent evt){
鼠标选择(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt){
Mouseexit选项(evt);
}
});
jLabel1.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,70));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jLabel1.setText(“我的世界”);
jLabel2.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,14));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jLabel3.addMouseListener(新java.awt.event.MouseAdapter(){
public void mouseenterned(java.awt.event.MouseEvent evt){
mouseclickfrog(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt){
mouseexitfrog(evt);
}
});
jButton4.setFont(新的java.awt.Font(“Arial圆角MT Bold”,0,24));//NOI18N
setForeground(新java.awt.Color(255、255、255));
jButton4.setText(“学分”);
jButton4.setboorder(null);
jButton4.setOpaque(false);
jButton3.setOpaque(false);
jButton4.setContentAreaFilled(false);
jButton4.addMouseListener(新java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent evt){
Jbutton4CLicked(evt);
}
public void mouseenterned(java.awt.event.MouseEvent evt){
JButton4hover 1(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt){
jButton4Mouseexitoptions(evt);
}
});
javax.swing.GroupLayout jPanel1Layout=新的javax.swing.GroupLayout(jPanel1);
setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanellayout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L