I have created a JApplet and I want to be able to clear the screen and draw new components depending on what button I click on. Right now the code below will clear the screen but it doesn't redraw the JTextFields (label_1 & label_2). However I did notice whenever I resize the applet(when it pops up in eclipse) the JTextFields suddenly reappear. Is there some type of refresh or restart method I need to call to get the components to draw correctly. Any tips or help in the right direction would be greatly appreciated. Here is my code so far.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Main_app extends JApplet
{
//Called when this is loaded into the browser.
public static Container content;
//public static JFrame frame;
public void init() {
//Create the frame and content manager
//frame = new JFrame("Cryptography Algorithms");
content = getContentPane();
setSize(600,600);
content.setBackground(Color.white);
//content.setSize(new Dimension(600,600));
//Set the flow for the content
FlowLayout mgr = new FlowLayout();
mgr.setHgap(10);
mgr.setVgap(10);
mgr.setAlignment(FlowLayout.LEFT);
content.setLayout(mgr);
//Add buttons to First Page
//Vigenere button
JButton vigenere_b = new JButton("Vigenere Cipher");
vigenere_b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
vigenere_gui();
}
});
content.add(vigenere_b);
//Inverse Matrix
JButton hill_b = new JButton("Hill Cipher");
hill_b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
hill_gui();
}
});
content.add(hill_b);
//Reset Button
JButton reset_b = new JButton("Reset");
reset_b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reset_gui();
}
});
content.add(reset_b);
}
//
// Clears the applet display
//
public static void reset_gui()
{
content.removeAll();
content.repaint();
}
//
// Set up display for vigenere cipher
//
public static void vigenere_gui()
{
reset_gui();
}
//
// Set up display for hill cipher
//
// public static Container hill_container;
public void hill_gui()
{
reset_gui();
content = getContentPane();
JTextField label_1 = new JTextField(70);
label_1.setBorder(BorderFactory.createEmptyBorder());
label_1.setText("Hill Cipher");
content.add(label_1);
JTextField label_2 = new JTextField(70);
label_2.setBorder(BorderFactory.createEmptyBorder());
label_2.setText("Enter the encryption matrix to get the decryption matrix");
content.add(label_2);
content.paint(content.getGraphics());
//content.setVisible(true);
}
}