Page 1 of 2 12 LastLast
Results 1 to 20 of 24
Like Tree1Likes

Thread: Why is my class not opening as a window?

  1. #1
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Why is my class not opening as a window?

    Ok so I have a few classes which are all parts of a GUI, I tried to get the buttons to open a new instance of class FirstGUI using actionperformed but it is not working (the class FirstGUI actually works and displays a GUI when I "run" it in NetBeans).

    public void actionPerformed(ActionEvent e) {

    if (e.getSource() == open) {
    gui1 = new FirstGUI();
    gui1.create();

    }

    As you can see I have properly declared and made a button called "open" which I have added the following code to:

    open.addActionListener(this);

    I have also made the class with the "open" button "implement" actionlistener by adding "implements actionlistener" at the end of the class declaration.

    Now when I run this class the GUI shows up fine but when I click the open button nothing happens (no window is opened).
    Anybody know what the problem may be?

    EDIT: gui1 is just an instance of the class FirstGUI.
    Last edited by 9a3iqa; 02-26-2013 at 05:05 PM.

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Why is my class not opening as a window?

    It's difficult to tell the problem because we don't know what gui1 is. But, I'm assuming it's probably a JFrame or something similar. If that's the case, you need to call gui1.setVisible(true);

  3. #3
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    No its an instance of the class FirstGUI.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why is my class not opening as a window?

    Consider telling us more about your problem and showing more code, code that is wrapped in [code] [/code] tags.

  5. #5
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by Fubarable View Post
    Consider telling us more about your problem and showing more code, code that is wrapped in [code] [/code] tags.
    Whenever I click on the "open" button what I want it to do is open the Jframe in the FirstGUI class. This Jframe is in the method "create" which belongs to the FirstGUI class. This is why I called create. Now I am not sure why but it should open instead all it gives me is a long list of exceptions in the Output....

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why is my class not opening as a window?

    You seem to be wanting to hide information from us that would help us answer your question despite our repeated requests, such as code, the actual exception messages and such. I'm not sure how we can help you until you give us enough information to do so.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by 9a3iqa View Post
    Now I am not sure why but it should open instead all it gives me is a long list of exceptions in the Output....
    You don't think it might be an idea to post the exception(s) plus stack trace?
    And the relevant parts of your code from which it was thrown.

    Otherwise all we can say is "you're doing something wrong".

    You wouldn't go to the mechanic and say "my car doesn't work" without showing your car and actually explaining in what way exactly it isn't working...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Ok I will do as you all say.
    Last edited by 9a3iqa; 02-27-2013 at 04:52 PM.

  9. #9
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Why is my class not opening as a window?

    Post the exceptions. They'd be a big help for us to help you.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Why is my class not opening as a window?

    Right, you've shown us the car now...how about about telling us exactly what's wrong (including exceptions and full stack trace).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by Tolls View Post
    Right, you've shown us the car now...how about about telling us exactly what's wrong (including exceptions and full stack trace).
    I modified the code to what you see and now no exceptions or errors appear (so I can't post any) but when the button is clicked nothing happens. I think I may have done something fundamentally wrong and this is why I am asking on a Java forum.....

  12. #12
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Why is my class not opening as a window?

    You didn't add the actionlistener to the registration button:
    Java Code:
    this.register = new JButton("Register");
    this.register.addActionListener(this);

  13. #13
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by SurfMan View Post
    You didn't add the actionlistener to the registration button:
    Java Code:
    this.register = new JButton("Register");
    this.register.addActionListener(this);
    I added the actionlistener to the register button and the button still does nothing when clicked.

  14. #14
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Why is my class not opening as a window?

    Home is a JPanel. In order for it to show up it needs to be placed in a Container. I think you want to use JFrame for that, just like you did in the main method in Home.
    Java Code:
    public void actionPerformed(ActionEvent e) {
           if (e.getSource() == register){
               Home one = new Home();
               JFrame frame = new JFrame();
               frame.getContentPane().add(one);
               frame.pack();
               frame.setVisible(true);
           }
        }
    }

  15. #15
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Ok I got it to work on my own, but thanks for the help anyway SurfMan I will rep you.

  16. #16
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Why is my class not opening as a window?

    Just so you know, when you post a reply, the content of your reply is sent to the users subscribed to this thread. Editing the post afterwards doesn't change what I find in my mailbox. So writing this makes me very angry:

    Dear SurfMan,

    9a3iqa has just replied to a thread you have subscribed to entitled - Why is my class not opening as a window? - in the New To Java forum of Java Programming Forum - Learn Java Programming.

    This thread is located at:
    http://www.java-forums.org/new-java/...-new-post.html

    Here is the message that has just been posted:
    ***************
    Ok I got it to work on my own, thanks for nothing.
    ***************
    <rant>
    I find this highly offensive. Programmers in this forum are people that spent their valuable time helping you with your coding issues. We don't *need* to do this. You should be a bit more (read: a whole lot more) appreciative to the ones that solve your petty problems.

    I hope a moderator reads this and swings his banstick, or at least give you an official warning.
    </rant>

  17. #17
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    I don't care if your angry, I gave you positive rep for attempting to help me and it wasn't even directed at you. Maybe I shouldn't have bothered with an attitude like yours.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by 9a3iqa View Post
    I don't care if your angry, I gave you positive rep for attempting to help me and it wasn't even directed at you. Maybe I shouldn't have bothered with an attitude like yours.
    Considering how long it took for you to actually supply us with information that we could use to provide help I suggest you look into your own attitude, and expectations. This is, after all, a site manned by volunteers. Spending our time trying to extract information from a poster in order to help them with their problem is not the best use of our time. Help us to help you, is what it boils down to.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    9a3iqa is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: Why is my class not opening as a window?

    Quote Originally Posted by Tolls View Post
    Considering how long it took for you to actually supply us with information that we could use to provide help I suggest you look into your own attitude, and expectations. This is, after all, a site manned by volunteers. Spending our time trying to extract information from a poster in order to help them with their problem is not the best use of our time. Help us to help you, is what it boils down to.
    Yes ok I understood that point, why is this forum so depressing.....

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Why is my class not opening as a window?

    Oh I don't know...you should see the office parties.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Page 1 of 2 12 LastLast

Similar Threads

  1. Restriction about opening multiple window [SOLVED]
    By UJJAL DHAR in forum New To Java
    Replies: 3
    Last Post: 06-29-2012, 05:52 AM
  2. How to set Default opening window in Swing?
    By asifzbaig in forum AWT / Swing
    Replies: 0
    Last Post: 02-09-2012, 07:06 PM
  3. opening applet in seperate window vs in the page.
    By bentley4 in forum Java Applets
    Replies: 5
    Last Post: 01-21-2012, 05:43 AM
  4. Oracle Forms Opening in single Java window
    By jav786 in forum Java Applets
    Replies: 0
    Last Post: 03-31-2011, 10:53 AM
  5. opening default browser window in invisible mode
    By robby14 in forum Advanced Java
    Replies: 1
    Last Post: 02-20-2010, 01:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •