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: GUI Problem

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default GUI Problem

    I'm making a GUI that has the user input a student's information into the GUI and then I write the information to a file.

    My problem is that the program doesn't seem to wait for the user to enter the information to continue the program....it just keeps executing the program, and then by the time the user enters the info the rest of the program has been executed.

    Here's my code:

    public static void main(String[] args)
            {
                    StudentData frame = new StudentData();
     
                    RandomAccessFile raf = null;
     
                    raf = frame.receiveFile();
     
                    frame.enterStudentData();
     
                    frame.setTitle("Student Data");
                    frame.setSize(1000,650);
                    frame.setLocationRelativeTo(null);
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     
                    frame.setVisible(true);
     
                    System.out.println("And the fname = " + frame.fname);
     
                    frame.outputStudentData(raf);
            }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI Problem

    With GUI, you show a form with input fields and wait for the user to enter his input and tell the program that the input is ready to be retrieved from the form. A common way to do that is with a button the user can press.

    setVisible() doesn't wait. It displays the GUI and returns to the next statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Re: GUI Problem

    Thanks for the response!

    I understand what you're saying, but, unfortunately, I have no idea how to make the user click a button that signals the program to retrieve the information.

    I am totally new to GUI and I've been looking online but it seems like everything is really convoluted. Any advice?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: GUI Problem

    Take a look at the tutorial:
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    It's not something you can pickup in a few hours.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. GUI problem
    By Techstudent in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 24th, 2013, 07:17 AM
  2. First GUI Problem
    By shodai in forum AWT / Java Swing
    Replies: 5
    Last Post: March 31st, 2013, 04:27 PM
  3. GUI problem
    By Fantasy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 21st, 2011, 09:09 PM
  4. GUI problem
    By Reem in forum AWT / Java Swing
    Replies: 6
    Last Post: November 15th, 2010, 09:45 AM
  5. GUI Problem
    By bulldog in forum AWT / Java Swing
    Replies: 1
    Last Post: December 11th, 2009, 01:47 PM