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 3 of 3

Thread: opening a new jframe using a seperate file

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default opening a new jframe using a seperate file

    Microsoft Windows 7
    Netbeans 7.0.1 with cygwin compiler / debugger

    I must admit I am completely new to Java programming, and have been completely befuddled by something that should seem so simple. I am learning Java by creating a very simple POS program, but have run into a snag. I have 2 frames (spos.java / spos_customer.java).

    spos.java simply has buttons that are the starting point of the program. Each button is supposed to take the user to another section of the program that they want to work with. Currently I am working on the sPOS button, which ideally will open the jframe located in spos_customer for the user to interact with.

    To be quite honest, I have been searching most of the day with google trying to find just one example of a program that will open a frame from a different file using an action event listener, as well as reading tutorials I thought would help me understand the subject. In this sense I have no idea how java works or handles calling and using components in different files. I dont even know where to start =(

    /*spos.java*/
    private void sposActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

    }

    My question is hopefully simple to answer. What code goes in the above to call the spos_customer file and tells it to load? Is that even possible? I want to hide spos.java and show spos_customer for the user to interact with.

    /*Edit*/

    I figured out what I needed to do. I cant believe I looked at the answer so many times today without understanding it. java is like arabic to me, vs C++ which would be english. Apparently you dont have to "call" the other file at all, simply create an instance of the object you want from the other file.

    spos_customer customerScreen = new spos_customer();
    customerScreen.setVisible(true);

    ^^ that is what belonged there...
    Last edited by bigblondguy; October 30th, 2011 at 09:26 PM. Reason: figured it out


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: opening a new jframe using a seperate file

    or just: new spos_customer();

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Location
    Polonnaruwa
    Posts
    6
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: opening a new jframe using a seperate file

    spos_customer customerScreen = new spos_customer();
    this.dispose();
    customerScreen.setVisible(true);

Similar Threads

  1. Windows 7 - jar file not opening a window
    By Yaten13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 10th, 2011, 06:53 PM
  2. How to seperate several messages in a byte buffer
    By perl0101 in forum Java Networking
    Replies: 4
    Last Post: April 12th, 2011, 06:29 PM
  3. Opening a file with a java program
    By hafunui in forum Java Theory & Questions
    Replies: 4
    Last Post: March 1st, 2011, 04:52 PM
  4. Switching between frames from a seperate class
    By kurt-hardy in forum AWT / Java Swing
    Replies: 4
    Last Post: February 14th, 2011, 04:19 AM
  5. Opening a File for User
    By aussiemcgr in forum Java Theory & Questions
    Replies: 3
    Last Post: July 29th, 2010, 04:00 AM