This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help with paint to panel

Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Anybody? Is it even possible?
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need to do is use a component like the following to display your image in your applet -

They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic