Hi, I'm new to java. I am currently working on a java applet (stand alone - no html stuff) and I'm having a little problem. When I run the following code, nothing appears on the applet until i resize the frame while it's running (and then it works just fine):
public class WidgetStore extends JApplet implements ActionListener { //declare variables and images ImageIcon introScreen = new ImageIcon("IntroScreen.gif"); JLabel introScreenLabel = new JLabel(introScreen);
//construct components and containers JButton proceedButton = new JButton("Enter");
Container c = getContentPane(); JPanel topIntroPanel = new JPanel(); JPanel bottomIntroPanel = new JPanel();
public void paint(Graphics g) { }
public void init() { //set frame properties setSize(350,325);
//create panels and add or change various components c.setLayout(new BorderLayout()); topIntroPanel.setLayout(new FlowLayout()); bottomIntroPanel.setLayout(new FlowLayout()); c.add(topIntroPanel, NORTH); c.add(bottomIntroPanel, CENTER);
I don't understand what's causing the applet to not display anything until a resizing of the frame occurs....moving the frame around doesn't do anything either.
I once got the advice that it improves the performance not to override the paint method, but to override the paintComponent method. Don't forget to call super.paintComponent(g) first.
Even better: If you just draw on one single panel, oerrides this panel's methods instead of the applet's methods.