Article View: borland.public.jbuilder.java.language
Article #17857Scrolling Large images in small view?
From: Dominique Louis
Date: Sat, 12 Sep 1998 00:00
Date: Sat, 12 Sep 1998 00:00
153 lines
4107 bytes
4107 bytes
Hi I'am new to Java and am trying to write an applet that will allows me
to Scroll a large JPEG map but
in a small viewing area, ie I load the whole map but only display small
portions of it depending on whether the user clicks and up, down, left
or right button ( NOT Scroll bars ).
Here is my MainMap code... Can anyone suggest where I'm going wrong.
I'm not sure if I'm using the copyArea function correctly or that my
co-ordinate system is right.
> import java.awt.*;
> import java.awt.event.*;
>
>
> public class MainMap extends Canvas
> {
> Point TL;
> int viewwidth, viewheight;
>
> Image BufferedImage;
> Image MainMapImage = null;
>
> Graphics offScreen, mainGraphics;
>
> public MainMap( Image image, int viewablewidth, int viewableheight )
> {
> MainMapImage = image;
> if( MainMapImage != null)
> {
> mainGraphics = MainMapImage.getGraphics( );
> }
> // Sort out offscreen Image
> try
> {
> BufferedImage = createImage( viewablewidth, viewableheight );
> offScreen = BufferedImage.getGraphics( );
> }
> catch( Exception e )
> {
> offScreen = null;
> }
>
> viewwidth = viewablewidth;
> viewheight = viewableheight;
>
>
> addMouseListener(new MouseAdapter()
> {
> public void mouseEntered(MouseEvent e)
> {
> requestFocus();
> }
> public void mouseClicked(MouseEvent e)
> {
> }
>
> public void mouseDragged(MouseEvent e)
> {
> }
>
> public void mouseMoved(MouseEvent e)
> {
> }
>
> public void mousePressed(MouseEvent e)
> {
> }
>
> public void mouseReleased(MouseEvent e)
> {
> }
>
> public void mouseExited(MouseEvent e)
> {
> }
> } );
> }
>
> public void setImage( Image image )
> {
> MainMapImage = image;
> repaint();
> }
>
> public Image getImage( )
> {
> return MainMapImage;
> }
>
> public void setTopLeft( Point tl )
> {
> this.TL = tl;
> repaint();
> }
>
> public Point getTopLeft( )
> {
> return TL;
> }
>
> public Dimension getPreferredSize( )
> {
> return new Dimension( viewwidth, viewheight );
> }
>
> public Dimension getMinimumSize( )
> {
> return getPreferredSize( );
> }
>
> public void update( Graphics g )
> {
> paint( g );
> }
>
> public void paint(Graphics g)
> {
> if ( offScreen != null )
> {
> MainMapPaint( offScreen );
> g.drawImage( BufferedImage, 0, 0, this );
> }
> else
> {
> g.copyArea(TL.x, TL.y, viewwidth , viewheight, 0, 0);
> MainMapPaint( g );
> }
>
> }
>
> public void MainMapPaint( Graphics g )
> {
> g.draw3DRect( 0, 0, viewwidth, viewheight, true );
> g.drawImage( MainMapImage, 1, 1, viewwidth - 1, viewheight - 1, this );
> }
> }
>
--
Ciao,
Dominique Louis
*********************************************************
** To Do Nothing is to Collaborate with the oppressor **
*********************************************************
===========================================================
From . . . . . . . : Dominique Louis
( Savage Software Solutions )
Web Site . . . . . : http://www.SavageSoftware.com.au
Email. . . . . . . : Dominique_Louis@BigPond.com
===========================================================
Technical Details
Message-ID:
<35FA748D.F411691F@BigPond.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,cdbf02f60b72ce2f,start X-Google-Attributes: gidf74b3,public From: Dominique Louis <Dominique_Louis@BigPond.com> Subject: Scrolling Large images in small view? Date: 1998/09/12 Message-ID: <35FA748D.F411691F@BigPond.com> X-Deja-AN: 390413887 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Savage Software Solutions Mime-Version: 1.0 Reply-To: Dominique_Louis@BigPond.com Newsgroups: borland.public.jbuilder.java.language