by Dinesh Thakur

 

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
public class JavaExampleScrollPictureInJApplet extends JApplet
 {
      public JavaExampleScrollPictureInJApplet()
       {
        Container Cntnr = getContentPane();
        JViewport ViewPrt = new JViewport();
        JPanel Pnl = new JPanel();
        Pnl.add(new JLabel(new ImageIcon("Koala.jpg")));
        ViewPrt.setView(Pnl);
        Cntnr.add(ViewPrt,BorderLayout.CENTER);
        Cntnr.add(new ButtonPanel(ViewPrt),BorderLayout.SOUTH);
      }
 }
       class ButtonPanel extends JPanel implements ActionListener
         {
              JViewport ViewPrt;
              JButton BtnLft = new JButton("Scroll Left");
              JButton BtnUp = new JButton("Scroll UP");
              JButton BtnDwn = new JButton("Scroll Down");
              JButton BtnRght = new JButton("Scroll Right");
              public ButtonPanel(JViewport VwPort)
               {
                  ViewPrt = VwPort;
                   add(BtnLft);
                   add(BtnUp);
                   add(BtnDwn);
                   add(BtnRght);
                  BtnLft.addActionListener(this);
                  BtnUp.addActionListener(this);
                  BtnDwn.addActionListener(this);
                  BtnRght.addActionListener(this);
               }
                   public void actionPerformed(ActionEvent e1)
                  {
                      Point Pstn = ViewPrt.getViewPosition();
                      if(e1.getSource() == BtnLft) Pstn.x += 10;   
                      else if(e1.getSource() == BtnUp) Pstn.y += 10;   
                      else if(e1.getSource() == BtnDwn) Pstn.y -= 10;   
                      else if(e1.getSource() == BtnRght) Pstn.x -= 10;   
                       ViewPrt.setViewPosition(Pstn);
                   }
        }
/*<APPLET  CODE=JavaExampleScrollPictureInJApplet.class WIDTH=700  HEIGHT=200 ></APPLET>*/
JViewport in Java Swing Example