Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Help with paint to panel

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i need to paint a gif(myImage) onto a panel(panel1) in my applet. I want my program to use only AWT components no Swing. I can paint the gif no problem onto the applet canvas but just cant get it to paint onto panel1 or any other panel for that matter, it always just appears on the canvas even though i am referencing the panel. A reply from an earlier post was "You would have to extend Panel, override paint(), and use it for the class of your panel1 object." which i have tried without success. Can anybody show me how to do this? If somebody could edit my code below with the solution or point me in the direction of a post that has a simple example of this it would be very much apreciated.
Thanks Mike
package coursework;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Image;
public class Applet1
extends Applet {
Image myImage;
private boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
Panel Lower = new Panel();
Panel Upper = new Panel();
CardLayout cardLayout1 = new CardLayout();
Panel Help = new Panel();
GridLayout gridLayout1 = new GridLayout();
Panel panel1 = new Panel();
Panel Game = new Panel();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
//Construct the applet
public Applet1() {
//Initialize the applet
public void init() {
try {
catch (Exception e) {
//Component initialization
private void jbInit() throws Exception {
this.add(Lower, BorderLayout.CENTER);
Lower.add(Help, "panel1");
Lower.add(Game, "Game");
Game.add(panel1, null);
this.add(Upper, BorderLayout.NORTH);, "Game");
myImage = getImage(getCodeBase(), "jar.gif");
MediaTracker mt = new MediaTracker(this.Lower);
mt.addImage(myImage, 0);
try {
mt.waitForAll(); // blocks here until Image is fully downloaded
catch (InterruptedException e) {
public void paint(Graphics g) {
g.drawImage(myImage,1, 1,this.Lower);
//Start the applet
public void start() {
//Stop the applet
public void stop() {
//Destroy the applet
public void destroy() {
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
//Get parameter info
public String[][] getParameterInfo() {
return null;
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody? Is it even possible?
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to do is use a component like the following to display your image in your applet -

You get good luck from rubbing the belly of a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic