Java Help Needed
Moderator: Moderators
-
ArwenEarendil
- PPT Warrior

- Posts: 765
- Joined: Thu Jun 17, 2004 1:28 pm
- Location: Among the crayons on my desk..
Java Help Needed
I'm redoing a textbased Computer Aided Instruction program I created last year. The thing is, my teacher wants the program with a GUI. I'm not doing it as an applet, but with AWT and Swing. So basically, a standalone program.
I just dived right into graphics, so I'm basically drawing from textbook info and previous knowledge I had on Java, C++ and OOProg. So please excuse the bad code.
The problem is this. The main goal (for me anyways) is to keep the program to ONE window. That means that in the start window (say, the menu) I click a button, the window is supposed to clear and show me a completely different interface. The action passes right into the ActionListener, and works right until after repaint(); After removing previous panels and repainting, I try to add new panels. Except, it doesn't work.
Thoughts? Suggestions? Help? Anything is appreciated.
You'll notice that I tried several methods (via commenting out). I also didn't put comments regarding what each part was supposed to do, so if you don't understand what my purpose was supposed to be, please ask.
Here are the links:
http://www.geocities.com/whitemagicdesi ... troyer.txt
http://www.geocities.com/whitemagicdesi ... oveAll.txt
I just dived right into graphics, so I'm basically drawing from textbook info and previous knowledge I had on Java, C++ and OOProg. So please excuse the bad code.
The problem is this. The main goal (for me anyways) is to keep the program to ONE window. That means that in the start window (say, the menu) I click a button, the window is supposed to clear and show me a completely different interface. The action passes right into the ActionListener, and works right until after repaint(); After removing previous panels and repainting, I try to add new panels. Except, it doesn't work.
Thoughts? Suggestions? Help? Anything is appreciated.
You'll notice that I tried several methods (via commenting out). I also didn't put comments regarding what each part was supposed to do, so if you don't understand what my purpose was supposed to be, please ask.
Here are the links:
http://www.geocities.com/whitemagicdesi ... troyer.txt
http://www.geocities.com/whitemagicdesi ... oveAll.txt
Last edited by ArwenEarendil on Fri Nov 03, 2006 5:40 pm, edited 1 time in total.
. Set by Medusa ♥
-
Universal Senja
- Honorary Member

- Posts: 731
- Joined: Tue Jun 01, 2004 3:26 pm
I believe I know what you're trying to do. Out of curiosity, are you using a Container?
-
ArwenEarendil
- PPT Warrior

- Posts: 765
- Joined: Thu Jun 17, 2004 1:28 pm
- Location: Among the crayons on my desk..
Universal Senja wrote:I believe I know what you're trying to do. Out of curiosity, are you using a Container?
Yes. However, I just looked at my previous post (I was in a rush yesterday) and I posted the same link. -_-; That has been corrected now. The main file is TestRemoveAll.txt
In the ActionListener, this is what happens:
Code: Select all
contentPane.removeAll(); //or contentPane.remove(Component component)
repaint(); //works right up to here
contentPane.add(Component component); //doesn't workIn my mind, this works, but it's probably wrong. If I compile the project, I just get a blank window after the object is passed to the ActionListener.
. Set by Medusa ♥
-
Universal Senja
- Honorary Member

- Posts: 731
- Joined: Tue Jun 01, 2004 3:26 pm
-
ArwenEarendil
- PPT Warrior

- Posts: 765
- Joined: Thu Jun 17, 2004 1:28 pm
- Location: Among the crayons on my desk..
-
Universal Senja
- Honorary Member

- Posts: 731
- Joined: Tue Jun 01, 2004 3:26 pm
-
ArwenEarendil
- PPT Warrior

- Posts: 765
- Joined: Thu Jun 17, 2004 1:28 pm
- Location: Among the crayons on my desk..
*glomps*
IT WORKS!
By itself, it didn't work.. if froze after a while. But I did a combo of repaint() and contentPane.validate(); and it works! Thank you! ^_^
So this is what the ActionListener looked like in the end:
IT WORKS!
By itself, it didn't work.. if froze after a while. But I did a combo of repaint() and contentPane.validate(); and it works! Thank you! ^_^
So this is what the ActionListener looked like in the end:
Code: Select all
public void actionPerformed (ActionEvent e)
{
Container contentPane = getContentPane();
if (e.getActionCommand().equals("Clear"))
{
contentPane.remove(buttonPanel);
contentPane.remove(textPanel);
repaint();
contentPane.add(textPanel2, BorderLayout.CENTER);
contentPane.add(buttonPanel2, BorderLayout.SOUTH);
contentPane.validate();
}
else if(e.getActionCommand().equals("Return"))
{
contentPane.remove(textPanel2);
contentPane.remove(buttonPanel2);
repaint();
contentPane.add(textPanel, BorderLayout.CENTER);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
contentPane.validate();
}
else
{
System.exit(0);
}
}
. Set by Medusa ♥
-
Universal Senja
- Honorary Member

- Posts: 731
- Joined: Tue Jun 01, 2004 3:26 pm