Mike Calder

Greenhorn
+ Follow
since Mar 28, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Calder

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 {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
Upper.setBackground(Color.red);
Upper.setVisible(true);
Lower.setBackground(Color.orange);
Lower.setVisible(true);
Lower.setLayout(cardLayout1);
panel1.setBackground(Color.cyan);
Game.setBackground(Color.white);
Game.setLayout(gridLayout1);
this.add(Lower, BorderLayout.CENTER);
Lower.add(Help, "panel1");
Lower.add(Game, "Game");
Game.add(panel1, null);
this.add(Upper, BorderLayout.NORTH);
cardLayout1.show(Lower, "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;
}
}
19 years ago