
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Applet1  extends Applet implements MouseListener,AdjustmentListener,MouseMotionListener,ItemListener
{
	Font font = null;
	Image imgSmall = null;
	Image imgBig = null;
	Image imgTmp = null;
	Image buffer = null;
	boolean flicker = true;
	Dimension dim =null;
	Scrollbar vscroll,hscroll;
	
	static boolean small = true;
	
	public Applet1()
	{
	}
	
	
	public void init()
	{
		//this.setSize( 800, 600 );
		this.setName("aplet-moj pic");
	
		font = new Font("Courier New", Font.BOLD, 18 );
		setBackground( Color.BLUE );
		imgSmall = getImage( getDocumentBase(), "mySmall.jpg");
		imgBig = getImage( getDocumentBase(), "myBig.jpg");
		imgTmp = imgSmall;
		buffer = createImage( this.getWidth(), this.getHeight() );
		
		
		setLayout( new BorderLayout());
		
		vscroll = new Scrollbar( Scrollbar.VERTICAL, 0,3,0,  2048 - this.getHeight() );
		hscroll = new Scrollbar( Scrollbar.HORIZONTAL, 0,3,0, 1536 - this.getWidth() );
		
		add( vscroll, BorderLayout.EAST );
		add( hscroll, BorderLayout.NORTH);
		addMouseListener( this );
		addMouseMotionListener( this );
		vscroll.addAdjustmentListener(this);
		hscroll.addAdjustmentListener(this);
	}
	
	public void paint( Graphics dc )
	{
		dc.setColor( Color.red );
		dc.setFont( font );
		if( small )
		{
			dc.drawString("male zdjecie", 30, 40 );
			dc.drawImage( imgTmp, 30, 50, this );
		}
		else
		{
			dc.drawString("duze zdjecie", 30, 40 );
			dc.drawImage( imgTmp, 30 - hscroll.getValue(), 50 - vscroll.getValue(), this );
		}
	}
	
	/*public boolean imageUpdate( Image img, int flags, int x, int y, int w , int h )
	{
		if( (flags & ALLBITS)==0 )
		{    
			return true;
		}
		else
		{
			return false;
		}
	}*/
	
	public void start()
	{
	}
	public void stop()
	{
	}
	public void mouseClicked( MouseEvent e )
	{
		int button = e.getButton();
		switch( button )
		{
		case MouseEvent.BUTTON1 :
			small= small ? false:true;
			break;
		case MouseEvent.BUTTON2 :
			small= small ? false:true;
			break;
		case MouseEvent.BUTTON3 :
			small= small ? false:true;
			break;
		}
		
		if( !small )
			imgTmp = imgBig;
		else
			imgTmp = imgSmall;
		
		repaint();
	}
	public void mouseEntered( MouseEvent e ) {}
	public void mouseExited( MouseEvent e ){}
	public void mousePressed( MouseEvent e ) {}
	public void mouseReleased( MouseEvent e )
	{
		repaint();
	}

	public void adjustmentValueChanged(AdjustmentEvent e)
	{
		repaint();
	}

	public void mouseDragged(MouseEvent e)
	{
		vscroll.setValue( e.getY() );
		hscroll.setValue( e.getX() );
		flicker = false;
		repaint();
	}

	public void mouseMoved(MouseEvent e)
	{
		flicker = true;
	}

	public void itemStateChanged(ItemEvent e) 
	{
	}

}
