java applet source code

I am writing java applet which i will upload it to a webpage on net. i face with a problem .i don't know what is the source code for it.
I will add a button,and when i press it, it display another frame or link to another java applet. Inside the frame, there will have a button that can be pressed until 16 times,and when it is pressed the label on the button will change,and every time a image file( a.gif) will display beside the button, meaning that when the button is pressed, label on button will change and display a image file.
Example, i want the label on the button to display the number 0 to 16,and for every number on the button, there will also have 17 different image files will display with the response of the button.
Every time , the next image file display (at the same position for all the image file display), the previous one will change into the next image file.
At first, the label of the button is 0 and there also a image file display there.
can i do that?...pls tell me the java applet source code to write like that.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you increase the points.I can then
start to code and send it to you.
jeannieyeapAuthor Commented:
Dear vichu,
i hope u really can help me, i am willing to increase the point, but i don't sure that whether ur answer is suitable to my question, i hope u really understand what i mean.


I have what you need. Pllease try to compile the next source code and run in browser :

// Author Ovi
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class ImageViewer extends Applet {
      String imgs[] = {"1.gif", "2.gif", "3.gif", "4.gif"};
      Image images[] = new Image[4];
      Button b = null;
      public void init() {
          for(int i=0; i<imgs.length; i++) {
              try {
                  images[i] = getImage(new URL(getCodeBase().toString()+"/Images/"+imgs[i]));
              }catch(MalformedURLException e) {
                  System.out.println(" Bad URL for index : "+i+".");
            b = new Button("Press me");
            b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        ViewerFrame f = new ViewerFrame("Image viewer", images);
                        f.setLocation(100, 100);
                        f.setSize(250, 400);
      public class ViewerFrame extends Frame {
          public Image images[] = null;
          public Button b1;
          public Button b2;
          public int curentIndex = 0;
          private Image curentImage = null;
          public ViewerFrame(String title, Image imgStream[]) {
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                    Window w = e.getWindow();
              images = imgStream;
              curentImage = images[0];
          private void createButtons() {
              b1 = new Button("Back");
              b1.move(60, 30);
              b1.setSize(50, 20);
              if(curentIndex == 0)
              b1.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      if(curentIndex == 0)
                      b2.setLabel("" + curentIndex);
                      curentImage = images[curentIndex];
              b2 = new Button("" + curentIndex);
              b2.move(130, 30);
              b2.setSize(60, 20);
              b2.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      if(curentIndex < images.length -1)
                      if(curentIndex != 0)
                      b2.setLabel("" + curentIndex);
                      curentImage = images[curentIndex];
          public void update(Graphics g) {
          public void paint(Graphics g) {
              if(curentImage != null)
                  g.drawImage(curentImage, 35, 60, 180, 180, this);

HTML file

<TITLE>Ovi's Image viewer</TITLE>
<APPLET CODE=ImageViewer.class WIDTH=300 HEIGHT=300></APPLET>

This is more that you want in your question. To be more clear, you have in your oppened frame from applet TWO BUTTONS one for back return to previous image, and one labeled with curent image number wich you can use to go to next pic. The labels are updated automatically depending on your action.

This version is one demonstrative for only 4 pictures named "1.gif", "2.gif", "3.gif", "4.gif". For adding more images please modify this lines in the source code :

String imgs[] = {"1.gif", "2.gif", "3.gif", "4.gif"};//add more names
Image images[] = new Image[4];//change 4 to your number

In this version is required that you have the images stored in your codebase+Images directory.
If you want to change the URL from where you load the images, please modif. next line :

images[i] = getImage(new URL(getCodeBase().toString()+"/Images/"+imgs[i]));

images[i] = getImage(new URL("Your URL"+imgs[i]));

More : You can send parameters from html Page with the number of images, and names of images.

More, next episode......

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeannieyeapAuthor Commented:
Thanks Ovi!!!
Me too...:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.