Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Display image in applet viewer(Trouble viewing my jpg images)
Display image in applet viewer [message #708307] Tue, 02 August 2011 17:06 Go to next message
David  is currently offline David Friend
Messages: 2
Registered: August 2011
Junior Member
When I run my project in Eclipse's applet viewer, I cannot see my images. I can see other things such as JLabels. Also, when I create an identical copy in a simple tex editor and place all the files on my desktop, embed the applet into an html file and run javac Movies.java in the terminal, I can view the applet including images no problem.
I think I am setting up my project wrong, because I have tried it on both my mac and the school's pc.

This is the course I take to start my project:

select the default workspace

new Java Project

Project Name : Movies - then I click finish

New Class - I name that Movies also.

I drag and drop the images into the same src folder as Movies.java

Here is my code.
import javax.swing.*;
import java.awt.*;

/** Demonstrate drawing an image. **/
public class Movies extends JApplet
{
  public void init () {
    Container content_pane = getContentPane ();

    // Grab the image.
    Image img = getImage (getCodeBase (), "DeadMan.jpg");

    // Create an instanceof DrawingPanel
    DrawingPanel drawing_panel =  new DrawingPanel (img);

    // Add the DrawingPanel to the content pane.
    content_pane.add (drawing_panel);
  } // init

} // class ImageApplet

class DrawingPanel extends JPanel
{
  Image img;

  DrawingPanel (Image img)
  { this.img = img; }

  public void paintComponent (Graphics g) {
   super.paintComponent (g);

   // Use the image width & height to find the starting point
   int imgX = getSize ().width/2 - img.getWidth (this);
   int imgY = getSize ().height/2 - img.getHeight (this);

   //Draw image centered in the middle of the panel    
   g.drawImage (img, imgX, imgY, this);
  } // paintComponent

} // DrawingPanel 
Re: Display image in applet viewer [message #708376 is a reply to message #708307] Tue, 02 August 2011 18:54 Go to previous message
David  is currently offline David Friend
Messages: 2
Registered: August 2011
Junior Member
I got it to work. I placed my images in the bin folder instead of src.
Previous Topic:SED script plugin
Next Topic: ClassNotFoundException
Goto Forum:
  


Current Time: Sat Apr 27 03:32:05 GMT 2024

Powered by FUDForum. Page generated in 0.11251 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top