This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Applets and the fly likes Image+Button+applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Image+Button+applet" Watch "Image+Button+applet" New topic


Ramesh Devendra

Joined: Mar 30, 2001
Posts: 4
Thanks your kind response,
Q1.Previous day you send code in click event GIF file become
change(So our requiremet is fullfil)but one problem arise that
i want click button in out side of GIF image.please sir give
me send this code

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ImageButtonApplet02 extends Applet implements ActionListener{
private Vector v;
private int numOfImages;
private int currentImage;
private Button b;
public void init()
v = new Vector( 10 );
numOfImages = 0;
currentImage = 0;

// The next few lines add three images to the vector
// These were just some images I had laying around
// If you have numbered images it would be much better to
// make a loop that loops through all your images
// or perhaps pass all of them in as parameters to the
// applet... It's your decision.
Image tempImage = getImage(getCodeBase(),"c:/RAMESH/newbanner111.jpeg.jpg" );
v.insertElementAt( tempImage, numOfImages );
tempImage = getImage( getCodeBase(), "c:/RAMESH/fman_mainscreen.gif" );
v.insertElementAt( tempImage, numOfImages );
tempImage = getImage( getCodeBase(), "c:/RAMESH/mona.jpeg" );
v.insertElementAt( tempImage, numOfImages );
Button b = new Butto( "Next!" );
b.addActionListener( this );

add( b );

public void paint( Graphics g )
Image i = ( Image )v.elementAt( currentImage );
g.drawImage( i, 0, 0, this );

public void actionPerformed( ActionEvent e )
currentImage = (currentImage + 1 ) % numOfImages;

UBB code
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I am not sure what you mean by outside of image... if you want a border area around the image with a button on it that would be simple enough to do...

Basically, I moved most of the image stuff into an inner class, and then basically made the applet save the vector and handle the button... Is this what you wanted?
NOTE : I had problems with NullPointerExceptions unless I specifically initialized the ImagePanel with an Image... you may want to make ImagePanel a little more robust if you have problems...
[This message has been edited by Nathan Pruett (edited April 04, 2001).]

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Image+Button+applet
jQuery in Action, 3rd edition