Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Swing, JFrame simple questions!

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Swing, JFrame simple questions!

    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):
    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");
    }

    }
    }
    }
    Heres the second file!
    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");
    }

    }
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Swing, JFrame simple questions!

    So what do you seem to be stuck on?

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Swing, JFrame simple questions!

    In the IF statement that checks if password is correct I want to close the current (Password window) and open up the second window (Mainpage.java)

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Swing, JFrame simple questions!

    So what do you seem to be stuck on?

    We are playing this game backwards.
    You are supposed to ask the questions and read the replies.
    I'll save the rest of my questions for answers that are of interest to me.

Similar Threads

  1. bluej some questions about a simple car details class
    By infernocy in forum Object Oriented Programming
    Replies: 5
    Last Post: April 9th, 2012, 05:32 AM
  2. Questions on simple client-server app
    By worwhite in forum Threads
    Replies: 24
    Last Post: July 30th, 2011, 08:19 PM
  3. Paying for simple questions.
    By kmjt in forum Paid Java Projects
    Replies: 6
    Last Post: February 10th, 2011, 08:31 PM
  4. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM