mport java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.*;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;



public class Main extends JApplet implements ActionListener,ItemListener {
	//private Image im;	// image handler
	//private static final String IMAGE = "enviro2.jpg";
	
	//starFish tapakSulaiman = new starFish(this);
	
	public void init() {
   // getImageSimple();
	this.setSize(780,540);
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    
    JPanel input= new JPanel();
    input.setLayout(new GridLayout(1,4));
    
    
    
    ImageIcon fish = new ImageIcon("images/fish.jpg");
    JButton bFish= new JButton("Fish",fish);
    bFish.setLocation(10, 40);
    bFish.setSize(100,100);
    input.add(bFish);
   
    Icon starFish = new ImageIcon("starfish.jpeg");
    JButton bSFish= new JButton("Star Fish",starFish);
   // bFish.setSize(100,100);
    input.add(bSFish);
   
    Icon shell = new ImageIcon("shell.jpeg");
    JButton bShell= new JButton("Shell",shell);
   // bFish.setSize(100,100);
    input.add(bShell);
   
    Icon seaweed = new ImageIcon("seaweed.jpeg");
    JButton bSW= new JButton("Seaweed",seaweed);
   // bFish.setSize(100,100);
    input.add(bSW);
   
   pane.add(input,BorderLayout.SOUTH);
	}
	/*
	private void getImageSimple() {
		// get the image
		im = getImage(getDocumentBase(), IMAGE);
	}
	
	private void getImageWithMediaTracker() {
		// get image
		im = getImage(getDocumentBase(), IMAGE);

		// create and add Media Tracker
		MediaTracker tracker = new MediaTracker(this);
		// add the image to tracker and give it an id say 0
		tracker.addImage(im, 0);
		try {
			// start loading the image with Id = 0
			// in this case the image
			tracker.waitForID(0);
		} catch (InterruptedException e) {
			System.out.println("Error loading Image : " + e.getMessage());
		}
	}
*/
	
	
	
	
	public void actionPerformed(ActionEvent e) {
		 Object obj = e.getSource();
	}
	 public void itemStateChanged(ItemEvent f){
	    	
	    }
}

i do not have idea why the image does appear..by the way, the image is in folder images.

two thins i think is the problem is 1.you didn't specify the url of all the image location 2.if the url of the imageicon for fish didn't work out then try using absoulte address e.g c:/images/fish.jpg or gif
ImageIcon fish = new ImageIcon("c:/images/fish.jpg");

two thins i think is the problem is 1.you didn't specify the url of all the image location 2.if the url of the imageicon for fish didn't work out then try using absoulte address e.g c:/images/fish.jpg or gif
ImageIcon fish = new ImageIcon("c:/images/fish.jpg");

ImageIcon fish = new ImageIcon("c:\\images\\fish.jpg");

edit: for Windows OS

Edited 5 Years Ago by mKorbel: n/a

This article has been dead for over six months. Start a new discussion instead.