• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

image in panel

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
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
You would have to extend Panel, override paint(), and use it for the class of your panel1 object.
 
Michael Calder
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
 
Michael Calder
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anybody?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic