how can i get the back and forward buttons i created to act as a web browser and display the previous image?
<p>I have created ths program to view images from the file chooser. Each time an item is opened it is added to the stack. I created a back and forward Jbutton so they can act as they would in a web browser. How can i get it to re-display the images. It stays stuck on the same image. Is the call to my repaint method in the wrong place? I have tried sevarl areas but can't seem to get it right. Please help, thanks!</p>

<pre><code>import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.*;


public class browser1 extends JPanel  {
    private JFrame frame;
    private JFileChooser chooser;
    private Image picture;
    private int dx,dy;
    private int tos, tos2 ;
    private static final int arraySize = 500;
    private Image [] theStack;
    private Image [] stack2;
    private JPanel south;
    private JButton forward, back;

    /**
     * @param args
     */
    public static void main(String[] args) {
        browser1 n = new browser1();
    }

    public browser1() {
        theStack = new Image [arraySize];
        stack2 = new Image [arraySize];
        tos = -1;
        tos2 = -1;
        frame = new JFrame();
        frame.setBounds(100, 200, 900, 650);
        frame.setTitle("Pictures");
        Container cp = frame.getContentPane();
        cp.add(this,BorderLayout.CENTER);

        south = new JPanel();
        back = new JButton("Back");
        south.add(back);
        back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Image I = stack2[tos2];
                stack2[tos2] = null;
                tos2 -= 1;
                push(I);
                repaint();
            }
        });

        forward = new JButton("Forward");
        south.add(forward);
        forward.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            //  repaint();
                Image I = top();
                pop();
                tos2 += 1;
                stack2[tos2] = I;
                repaint();

            }
        });
        cp.add(south, BorderLayout.SOUTH);

        JMenuBar jmb = new JMenuBar();
        frame.setJMenuBar(jmb);
        frame.setVisible(true);

        JMenu file = new JMenu("File");
        jmb.add(file);
        chooser = new JFileChooser();
        chooser.setCurrentDirectory(null);

        JMenuItem open = new JMenuItem("Open");
        file.add(open);
        open.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String fname;
                String name = e.getActionCommand();
                dx += 20;
                dy += (dy &gt; 100) ? -dy : 20;
                int code = chooser.showOpenDialog(null);
                if (code == JFileChooser.APPROVE_OPTION) {
                    try {
                        fname = chooser.getSelectedFile().getPath();
                        picture = ImageIO.read(new File(fname));
                        push(picture);
                    }
                    catch (IOException ioe) {
                        System.out.println("oops");
                    }
                }// if  

            System.out.println("IM HERE");  
            }   
        });// Open-Action listener

        JMenuItem quit = new JMenuItem("Quit");
        file.add(quit);
        quit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);             
            }
        }); 
    }// Constructor

        public void paintComponent(Graphics g) {
            System.out.println("Painting");
            if (picture != null) {
                g.drawImage(picture,250,250,200,160,null);
            }
        }

        public void push(Image x){
            if (tos == theStack.length -1) {
                System.out.println ("The stack is FULL!"); return; 
            }
            else {
                tos += 1;
                theStack[tos] = x;
            //  repaint();
            }
        }

        public void pop(){
            theStack[tos] = null;
            tos -= 1;
        }

        public Image top () {
            return theStack[tos];
        }

        public boolean empty() {
            return tos == -1;
        }

        public boolean full() { 
            return tos == theStack.length -1;
        }
}
</code></pre>
