Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help repainting a panel inside a JApplet  RSS feed

 
Ruxandra Codreanu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

What I am trying to do is write an applet that gets an input from the user using JTextField and then outputs something using the same thing. So far, everything went well, but now I added a menu item "New" which should have the effect of clearing all the text inputed and I don't know how to do it. Here is the code for the applet:

public class Sudoku1Applet extends JApplet{

WholePanel newContentPane;

public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JMenuBar menubar = new JMenuBar();

JMenu menuFile = new JMenu("File");

JMenuItem newItem = new JMenuItem("New");
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
newWindow();
}
});
menuFile.add(newItem);

JMenuItem exitItem = new JMenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
quitApplication();
}
});
menuFile.add(exitItem);

menubar.add(menuFile);

setJMenuBar(menubar);
createGUI();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}

private void createGUI() {
newContentPane = new WholePanel(); // the panel which contains all the JTextFields
setContentPane(newContentPane);
}

private void newWindow(){
// WHAT TO DO HERE?
}

private void quitApplication() {
System.exit(0);
}
}

Thanks!
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would call a method of WholePanel that told it to reset the GUI, something like:


Then of course you'll have to give your WholePanel class a public void reset() method, and inside this method do the necessary housekeeping to clear your JTextPanes, reset your class fields, etc...

By the way, welcome to the Ranch! You'll want to read the FAQ's including how to ask a question on java ranch and how to use code tags.

Much luck!
 
Ruxandra Codreanu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein wrote:I would call a method of WholePanel that told it to reset the GUI, something like:


Then of course you'll have to give your WholePanel class a public void reset() method, and inside this method do the necessary housekeeping to clear your JTextPanes, reset your class fields, etc...

Much luck!


Thanks for the help! I made it work
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruxandra Codreanu wrote:
Thanks for the help! I made it work


Excelente! You're welcome!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!