Forums Register Login

image in panel

+Pie Number of slices to send: Send
Hi i am trying to add an gif onto a panel in my applet and am using this to paint it.
public void paint(Graphics g) {
g.drawImage(myImage, 1, 1, this.panel1);
}
thi image doesn't appear on panel1 though, it instead appears underneath on the applet canvas and in the wrong place aswell. It appears in 1,1 on the applet canvas not 1,1 on the panel. How do i make it appear on panel1? Any help would be really good cos its annoying me now.
+Pie Number of slices to send: Send
You would have to extend Panel, override paint(), and use it for the class of your panel1 object.
+Pie Number of slices to send: Send
Hi thanks for the reply, i have looked around messages for what you said to do, and have found some examples, but i have produced rubbish. Java is new to me and i am strugling. This is a coursework project, and i have produced a working version but it uses swing which they warned us against so i'm now trying with just AWT components. I added a bit in about extending the panel but really don't know what i'm doing. I've cut my code back to the basics so if someone could just show how to paint the gif on panel1 that would be a huge help. Thnks
package coursework;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Image;
public class JamJars
extends Applet {
private boolean isStandalone = false;
Image myImage;
BorderLayout borderLayout1 = new BorderLayout();
Panel lower = new Panel();
Panel upper = new Panel();
CardLayout cardLayout1 = new CardLayout();
Panel game = new Panel();
GridLayout gridLayout1 = new GridLayout();
Panel panel1 = new Panel();
class paintPanel
extends Panel {
public void paintPanel() {
}
public void paint(Graphics g) {
g.drawImage(1, 1, myImage, panel1);
}
}
//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 JamJars() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
myImage = getImage(getCodeBase(), "jar.gif");
//myGrap = getGraphics(myImage);
this.setVisible(true);
this.setLayout(borderLayout1);
MediaTracker mt = new MediaTracker(this);
mt.addImage(myImage, 0);
try {
mt.waitForAll(); // blocks here until Image is fully downloaded
}
catch (InterruptedException e) {
}
lower.setLayout(cardLayout1);
game.setLayout(gridLayout1);
game.setBackground(Color.white);
panel1.setBackground(Color.white);
this.add(lower, BorderLayout.CENTER);
this.add(upper, BorderLayout.NORTH);
lower.add(game, "game");
game.add(panel1, null);
}
//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;
}
}
+Pie Number of slices to send: Send
anybody?
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1296 times.
Similar Threads
applets
NullPointerException Applet Observer
Change text orientation on canvas
Help with paint to panel
drawImage to Panel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:05:11.