2021年4月23日星期五

Only a title bar pops up when im trying to access a GUI from another class via button

i'm a newbie programmer and im kinda stuck with this issue for 2 hours now. So my issue is that whenever i click the Register button, only a title bar (no contents at all) pops up in the upper left of my screen. How can I fix this? Thank you in advance

btnRegister = new JButton("Register");  btnRegister.addActionListener(new ActionListener() {  public void actionPerformed(ActionEvent e) {  AccountCreationGUI window = new AccountCreationGUI();  window.setVisible(true);  frame.dispose();                                }          });  btnRegister.setBounds(199, 170, 89, 23);  frame.getContentPane().add(btnRegister);  

AccountCreationGUI (I didnt add the other method to make this short)

package main;  import java.sql.*;    import java.awt.EventQueue;  import javax.swing.JFrame;  import java.awt.Color;  import javax.swing.JLabel;  import javax.swing.JOptionPane;  import javax.swing.JTextField;  import javax.swing.JPasswordField;  import javax.swing.JButton;  import java.awt.event.ActionListener;  import java.awt.event.ActionEvent;  import javax.swing.JPanel;  import java.awt.Window.Type;    public class AccountCreationGUI extends JFrame {        private JFrame frmToolInventory;      private JTextField textfield_firstname;      private JTextField textfield_lastname;      private JTextField textfield_age;      private JTextField textfield_username;      private JPasswordField passwordField;      private JPasswordField passwordField_1;      JFrame frame;      Connection connection = null;                  public static void main(String[] args) {          EventQueue.invokeLater(new Runnable() {              public void run() {                  try {                      AccountCreationGUI window = new AccountCreationGUI();                      window.frmToolInventory.setVisible(true);                  } catch (Exception e) {                      e.printStackTrace();                  }              }          });      }              public AccountCreationGUI() {          initialize();      }    public void initialize() {          frmToolInventory = new JFrame();          frmToolInventory.setResizable(false);          frmToolInventory.setTitle("Tool Inventory");          frmToolInventory.getContentPane().setBackground(new Color(0, 51, 51));          frmToolInventory.setBounds(100, 100, 534, 346);          frmToolInventory.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          frmToolInventory.getContentPane().setLayout(null);                    JLabel label_firstname = new JLabel("First Name");          label_firstname.setForeground(new Color(255, 255, 255));          label_firstname.setBounds(88, 67, 68, 14);          frmToolInventory.getContentPane().add(label_firstname);                    JLabel label_lastname = new JLabel("Last Name");          label_lastname.setForeground(Color.WHITE);          label_lastname.setBounds(88, 92, 68, 14);          frmToolInventory.getContentPane().add(label_lastname);                    JLabel label_username = new JLabel("Username");          label_username.setForeground(Color.WHITE);          label_username.setBounds(88, 142, 68, 14);          frmToolInventory.getContentPane().add(label_username);                    JLabel label_password = new JLabel("Password");          label_password.setForeground(Color.WHITE);          label_password.setBounds(88, 167, 68, 14);          frmToolInventory.getContentPane().add(label_password);                    JLabel label_reconfirmpassword = new JLabel("Re-confirm Password");          label_reconfirmpassword.setForeground(Color.WHITE);          label_reconfirmpassword.setBounds(88, 192, 101, 14);          frmToolInventory.getContentPane().add(label_reconfirmpassword);                    JLabel label_age = new JLabel("Age");          label_age.setForeground(Color.WHITE);          label_age.setBounds(88, 117, 68, 14);          frmToolInventory.getContentPane().add(label_age);                    textfield_firstname = new JTextField();          textfield_firstname.setBounds(224, 64, 144, 20);          frmToolInventory.getContentPane().add(textfield_firstname);          textfield_firstname.setColumns(10);                    textfield_lastname = new JTextField();          textfield_lastname.setColumns(10);          textfield_lastname.setBounds(224, 89, 144, 20);          frmToolInventory.getContentPane().add(textfield_lastname);                    textfield_age = new JTextField();          textfield_age.setColumns(10);          textfield_age.setBounds(224, 114, 144, 20);          frmToolInventory.getContentPane().add(textfield_age);                    textfield_username = new JTextField();                textfield_username.setColumns(10);          textfield_username.setBounds(224, 139, 144, 20);          frmToolInventory.getContentPane().add(textfield_username);                    passwordField = new JPasswordField();          passwordField.setBounds(224, 164, 144, 20);          frmToolInventory.getContentPane().add(passwordField);                    passwordField_1 = new JPasswordField();          passwordField_1.setBounds(224, 189, 144, 20);          frmToolInventory.getContentPane().add(passwordField_1);                    JButton button_CreateAccount = new JButton("Create");          button_CreateAccount.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent e) {                  createAccount();                  }          });          button_CreateAccount.setBounds(224, 220, 68, 23);          frmToolInventory.getContentPane().add(button_CreateAccount);                    JButton btnClear = new JButton("Clear");          btnClear.addActionListener(new ActionListener() {              public void actionPerformed(ActionEvent e) {                  clear();              }          });          btnClear.setBounds(302, 220, 68, 23);          frmToolInventory.getContentPane().add(btnClear);      }      }        
https://stackoverflow.com/questions/67235128/only-a-title-bar-pops-up-when-im-trying-to-access-a-gui-from-another-class-via-b April 24, 2021 at 02:25AM

没有评论:

发表评论