试图在java中隐藏jframe,但我的代码没有';不行?

试图在java中隐藏jframe,但我的代码没有';不行?,java,Java,是的,所以它不起作用,我还尝试了setVisible(False),它说了一些关于不能静态引用布尔值之类的东西。 这是我的密码你能帮我修一下吗?如果可能的话,我没有时间做这么小的改动来让它生效,谢谢。 为了使您的生活更轻松,您不必阅读我的全部代码,只需执行ctrl+f“okbtn” 我不是要求代码审查我想知道错误是什么+如果我能做些什么来修复它,或者如果有人愿意帮我,谢谢你的批评。顺便说一句,我做了大量的研究,看了各种各样的东西,但我看到的东西都对我有用。@Andremoni好的,代码审查问题的

是的,所以它不起作用,我还尝试了setVisible(False),它说了一些关于不能静态引用布尔值之类的东西。 这是我的密码你能帮我修一下吗?如果可能的话,我没有时间做这么小的改动来让它生效,谢谢。 为了使您的生活更轻松,您不必阅读我的全部代码,只需执行ctrl+f“okbtn”


我不是要求代码审查我想知道错误是什么+如果我能做些什么来修复它,或者如果有人愿意帮我,谢谢你的批评。顺便说一句,我做了大量的研究,看了各种各样的东西,但我看到的东西都对我有用。@Andremoni好的,代码审查问题的地方是开放的,但是如果代码没有按预期工作,它还没有准备好进行同行审查,它是关于CR的非主题,等等。向上投票。尝试将setVisible()移动到initGUI()的底部()尝试在
actionPerformed
方法之后立即删除
private void setVisible(布尔b){//TODO自动生成的方法存根}
。此方法对
JFrame
中的
setVisible(boolean b)
进行阴影处理,它为您显示和隐藏。显示您的帧确实有效,因为您使用
inst.setVisible(true)进行显示
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import javax.swing.*;
import java.awt.event.*;
import java.util.Arrays;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainMenu extends javax.swing.JFrame {
    private JLabel username;
    private JLabel passwordlbl;
    private JLabel Welco;
    private JButton Cancelbtn;
    private JButton OKbtn;
    private JTextField Usernametxt;
    double ss;

    /**
    * Auto-generated main method to display this JFrame
    */

    public static void main(String[] args) {
        //PASSWORD field to store new password inside
        //Passwordfld.setEchoChar('*');
        //Passwordfld.addActionListener(new AL());

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MainMenu inst = new MainMenu();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);

            }
        });
    }

    public MainMenu() {
        super();
        initGUI();

    }
    private static boolean isPasswordCorrect(char[] input) {
        boolean isCorrect = true;
        char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' };

        if (input.length != correctPassword.length) {
            isCorrect = false;
        } else {
            isCorrect = Arrays.equals (input, correctPassword);
        }

        //Zero out the password.
        Arrays.fill(correctPassword,'0');

        return isCorrect;
    }
    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            getContentPane().setLayout(null);
            getContentPane().setBackground(new java.awt.Color(11,101,149));

            username = new JLabel();
            getContentPane().add(username);
            username.setText("User Name:");
            username.setBounds(63, 113, 80, 16);

            passwordlbl = new JLabel();
            getContentPane().add(passwordlbl);
            passwordlbl.setText("Password:");
            passwordlbl.setBounds(63, 160, 72, 16);

            Usernametxt = new JTextField();
            getContentPane().add(Usernametxt);
            Usernametxt.setBounds(198, 110, 79, 23);

            final JPasswordField Passwordfld = new JPasswordField();
            // Passwordfld.setText("Secret");
            getContentPane().add(Passwordfld);
            Passwordfld.setBounds(198, 157, 79, 23);
            Passwordfld.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // System.out.println("Passwordfld.actionPerformed, event="+evt);
                // TODO add your code for Passwordfld.actionPerformed
            }
            });
            OKbtn = new JButton();
            getContentPane().add(OKbtn);
            OKbtn.setText("OK");
            OKbtn.setBounds(102, 217, 59, 23);
            OKbtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String passText = new String(Passwordfld.getPassword());

                String cmd = evt.getActionCommand();
                /*This where the the majority of the code is executed
                Once the user types his info in and clicks the "ok button" the code is then executed and then depending 
                if the user gets his info correct the system communicates with the user allowing them to know if they
                succeeded in logging in.*/
                if (OKbtn.getActionCommand().equals(cmd)) { // Process the password.
                    if (Usernametxt.getText().equals("Admin")&& (isPasswordCorrect(passText.toCharArray()))) {
                        JOptionPane.showMessageDialog(MainMenu.this,
                                "Password Accepted");
                        System.out.println("Password Accepted");
                        ItemsPage ItemsPage = new ItemsPage(ss);
                        this.setVisible(false);
                        ItemsPage.setVisible(true);

                    } else {
                        JOptionPane.showMessageDialog(MainMenu.this,
                                "Password Rejected");
                    System.out.println("Password Rejected: " + passText);

                    }

                    // Zero out the possible password, for security.
                    Arrays.fill(passText.toCharArray(), '0');

                    Passwordfld.selectAll();

                    /*
                     * else{ System.out.println("permition Rejected"); }
                     */

                    // else{}
                    /*
                     * if (Passwordfld = Password)= true) {
                     * System.out.println("permition granted");}
                     */
                }

            }

            private void setVisible(boolean b) {
                // TODO Auto-generated method stub

            }
            });

            Cancelbtn = new JButton();
            getContentPane().add(Cancelbtn);
            Cancelbtn.setText("Exit");
            Cancelbtn.setBounds(198, 217, 61, 23);
            Cancelbtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                System.exit(0);//shuts down the program
                    //System.out.println("Cancelbtn.actionPerformed, event="+evt);
                    //TODO add your code for Cancelbtn.actionPerformed
                }
            });

            Welco = new JLabel();
            getContentPane().add(Welco);
            Welco.setText("Welcome to Jstore please log in using your staff acount");
            Welco.setBounds(51, 19, 291, 16);





            pack();
            setSize(400, 300);
        } catch (Exception e) {
            //add your error handling code here
            e.printStackTrace();
        }

    }
    //static class AL implements ActionListener{
    //JPasswordField input = new JPasswordField();

    /*  char [] passy = input.getPassword();
        String p = new String (passy);{
        if (p.equals (Password)){
            JOptionPane.showMessageDialog(null, "Correct"); }
            else
            {       JOptionPane.showMessageDialog(null, "InCorrect");

        }
        */


    }