The Artima Developer Community
Sponsored Link

Java Answers Forum
Blank applet screen! need help asap plz!

3 replies on 1 page. Most recent reply: May 19, 2006 12:13 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Bobby Long

Posts: 2
Nickname: ralawar
Registered: May, 2006

Blank applet screen! need help asap plz! Posted: May 17, 2006 9:44 PM
Reply to this message Reply
Advertisement
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):

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.text.DecimalFormat;
import javax.swing.*;
import java.util.Date;
import static java.awt.BorderLayout.*;


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);

topIntroPanel.add(introScreenLabel);
topIntroPanel.setBackground(Colo r.black);

bottomIntroPanel.add(proceedButton);
bottomIntroPanel.setBackground(C olor.black);
}

public void actionPerformed(ActionEvent e)
{
}
}

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.

All help appreciated! Thanks!


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Blank applet screen! need help asap plz! Posted: May 17, 2006 10:16 PM
Reply to this message Reply
Why don't you paint anything?

Try calling
super.paint(g);
in your paint method.

Bobby Long

Posts: 2
Nickname: ralawar
Registered: May, 2006

Re: Blank applet screen! need help asap plz! Posted: May 18, 2006 12:29 AM
Reply to this message Reply
It works! Thanks! I am going to paint stuff in later, but I'm just slowly adding stuff into this applet for now.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Blank applet screen! need help asap plz! Posted: May 19, 2006 12:13 AM
Reply to this message Reply
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.

Flat View: This topic has 3 replies on 1 page
Topic: how to add or link an html page from a button in a JFrame Previous Topic   Next Topic Topic: javac debug=true - runtime performance

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use