Okay I am trying to make a small inventory system for educational purposes.
I have a password Jframe and when the password is typed correctly I want it to close the password frame and open up my second file (mainpage.java).
Here are the 2 codes!
First gui (Password frame):
Heres the second file!import javax.swing.; //access the jframe import java.awt.event.; import java.awt.*;
public class FirstGui {
private static String password = "password";
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame theGUI = new JFrame();
theGUI.setTitle("Thrift Store Inventory System");// Assigned the Gui title
theGUI.setSize(350, 100);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE); //Assigned closed operation
JLabel label = new JLabel("Enter Password");
JPanel panel = new JPanel();
theGUI.add(panel);
JPasswordField password = new JPasswordField(10);
password.setEchoChar('*');
password.addActionListener(new AL());
panel.add(label, BorderLayout.WEST);
panel.add(password, BorderLayout.EAST);
theGUI.setVisible(true);
}
static class AL implements ActionListener {
public void actionPerformed(ActionEvent e) {
JPasswordField input = (JPasswordField) e.getSource();
char[] passy = input.getPassword();
String p = new String(passy);
if (p.equals(password)){
************ CODE SHOULD BE HERE?!?! **************
}
else {
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
}
}
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane;
public class MainPage {
public static void main(String[] args) {
JFrame theGUI = new JFrame();
theGUI.setTitle("Thrift Store Inventory System");// Assigned the Gui title
theGUI.setSize(350, 100);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE); //Assigned closed
JMenuBar menubar = new JMenuBar();
theGUI.setJMenuBar(menubar);
JMenu file = new JMenu("File");
menubar.add(file);
JMenuItem exit = new JMenuItem("Exit");
file.add(exit);
JMenu help = new JMenu("Help");
menubar.add(help);
JMenuItem about = new JMenuItem("About");
help.add(about);
about.addActionListener(new aboutaction());
theGUI.setVisible(true);
class exitaction implements ActionListener {
public void actionPerformed (ActionEvent e) {
System.exit(0);
}
}
exit.addActionListener(new exitaction());
}
static class aboutaction implements ActionListener {
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "Created by Jks");
}
}
}