Results 1 to 5 of 5
- 02-16-2009, 02:36 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 38
- Rep Power
- 0
[SOLVED] Open a different class from the same package when button clicked.
Hello,
Im new here and fairly new to Java and object orientated programming. I have a pretty simple problem for you guys, but it is driving me insane.
I have two classes, one called LoginBox and the other called MainInterface. They are both in the same package called VMD. Both of these classes extend JFrame and are two seperate windows.
There is a button in LoginBox called "confirm". It has an actionListener attached to it which works (I have tested it with a simple println command). What I am trying to achieve, is when the user clicks the button "confirm" it closes the LoginBox and opens MainInterface.
This is what I have at the moment:
Java Code:public void actionPerformed(ActionEvent e) { LoginBox.setVisible(false); MainInterface.setVisible(true); }
I hope you can help. I really don't know what I am doing wrong.
- 02-16-2009, 03:16 PM #2
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
you are almost there....
just try to do with following under your actionPerformed section...
String action = a.getActionCommand();
if (action.equals("Comfirm")) {
.....setVisible(true);
................
hope it will help...
regards,
- Neeraj
- 02-16-2009, 03:19 PM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 286
- Rep Power
- 13
Java Code:public void actionPerformed(ActionEvent e) { this.setVisible(false); MainInterface mi=new MainInterface(); mi.setVisible(true); }
- 02-16-2009, 04:11 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 38
- Rep Power
- 0
Hurrah!!! it worked :o
Thank you so much dswastik, i've spent hours trying to get that work. I thought it had something to do with telling the program MainInterface is not in that class, I just didn't know how to write that in Java Syntax.
Thank you to neeraj.singh, I now know how to assign multiple buttons to do different things; Atleast, I think that is what your code is referring to.
- 02-16-2009, 04:20 PM #5
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
[SOLVED] How to destroy a process when a button is clicked?
By pranav13 in forum AWT / SwingReplies: 11Last Post: 02-13-2009, 01:52 PM -
[SOLVED] Compiling Package Class
By nwboy74 in forum New To JavaReplies: 3Last Post: 11-15-2008, 12:19 AM -
Display success message in same page when submit button is clicked
By am17mu in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-29-2008, 11:56 AM -
Compiling a class in a package from cmd
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 11:27 AM
Bookmarks