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.
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);
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.
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
Fubarable
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....
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.
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
9a3iqa
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...
Re: Why is my class not opening as a window?
Ok I will do as you all say.
Re: Why is my class not opening as a window?
Post the exceptions. They'd be a big help for us to help you.
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).
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
Tolls
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.....
Re: Why is my class not opening as a window?
You didn't add the actionlistener to the registration button:
Code:
this.register = new JButton("Register");
this.register.addActionListener(this);
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
SurfMan
You didn't add the actionlistener to the registration button:
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.
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.
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);
}
}
}
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.
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:
Quote:
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>
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.
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
9a3iqa
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.
Re: Why is my class not opening as a window?
Quote:
Originally Posted by
Tolls
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.....
Re: Why is my class not opening as a window?
Oh I don't know...you should see the office parties.