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.