Hi, can someone help me? I have two Jframes: Frame and MainFrame.
My problem is they both show at the same time.
If the login is correct MainFrame opens and Frame closes.
import javax.swing.*;
public class Main extends JFrame{
public static void main(String args[]) {
//Frame Window /Login Window
Frame fram = new Frame();
fram.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fram.setSize(200,150);
fram.setVisible(true);
fram.setResizable(false);
//MainFrame Window
MainFrame seal = new MainFrame();
seal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
seal.setSize(200,150);
seal.setVisible(true);
seal.setResizable(true);
}}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame extends JFrame{
private JButton login;
private JTextField user;
private JPasswordField pass;
public Frame(){
super("Login"); // title
setLayout(new FlowLayout());
user = new JTextField(10);
add(user);
pass = new JPasswordField(10);
add(pass);
login = new JButton("Login");
add(login);
maria louise = new maria();
login.addActionListener(louise);
}
public class maria implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(user.getText().trim().length()== 0 || pass.getText().length()==0)
JOptionPane.showMessageDialog(null, "Please fill out both of the textbox");
else if(user.getText().equals("12345") && pass.getText().equals("12345"))
JOptionPane.showMessageDialog(null, " WELCOME");
else
JOptionPane.showMessageDialog(null,"Wrong Username or Password");
}}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainFrame extends JFrame{
private JLabel item1;
private JTextField item2, item3;
public MainFrame(){
super("Main Window");
setLayout(new FlowLayout());
item1 = new JLabel("Welcome");
item1.setToolTipText("Hello");
add(item1);
item2 = new JTextField(15);
add(item2);
item3 = new JTextField(15);
add(item3);
}}