Results 1 to 20 of 24
- 02-26-2013, 04:43 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
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.
- 02-26-2013, 04:48 PM #2
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
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);
- 02-26-2013, 04:58 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
Re: Why is my class not opening as a window?
No its an instance of the class FirstGUI.
-
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.
- 02-26-2013, 06:04 PM #5
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
Re: Why is my class not opening as a window?
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....
-
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.
- 02-26-2013, 06:19 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Why is my class not opening as a window?
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.
- 02-26-2013, 11:08 PM #8
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
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.
- 02-27-2013, 02:01 AM #9
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Re: Why is my class not opening as a window?
Post the exceptions. They'd be a big help for us to help you.
- 02-27-2013, 09:47 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 02-27-2013, 10:01 AM #11
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
Re: Why is my class not opening as a window?
- 02-27-2013, 10:17 AM #12
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
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);
- 02-27-2013, 03:38 PM #13
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
- 02-27-2013, 03:45 PM #14
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
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); } } }
- 02-27-2013, 04:15 PM #15
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
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.
- 02-27-2013, 04:27 PM #16
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
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:
<rant>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.
***************
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>
- 02-27-2013, 04:42 PM #17
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
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.
- 02-27-2013, 05:06 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Why is my class not opening as a window?
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.
- 02-27-2013, 05:10 PM #19
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
- 02-27-2013, 05:30 PM #20
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Restriction about opening multiple window [SOLVED]
By UJJAL DHAR in forum New To JavaReplies: 3Last Post: 06-29-2012, 05:52 AM -
How to set Default opening window in Swing?
By asifzbaig in forum AWT / SwingReplies: 0Last Post: 02-09-2012, 07:06 PM -
opening applet in seperate window vs in the page.
By bentley4 in forum Java AppletsReplies: 5Last Post: 01-21-2012, 05:43 AM -
Oracle Forms Opening in single Java window
By jav786 in forum Java AppletsReplies: 0Last Post: 03-31-2011, 10:53 AM -
opening default browser window in invisible mode
By robby14 in forum Advanced JavaReplies: 1Last Post: 02-20-2010, 01:50 AM


1Likes
LinkBack URL
About LinkBacks


Bookmarks