This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Image+Button+applet" Watch "Image+Button+applet" New topic
Author

Image+Button+applet

Ramesh Devendra
Greenhorn

Joined: Mar 30, 2001
Posts: 4
Sir,
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 response.you send this code

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
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 );
numOfImages++;
tempImage = getImage( getCodeBase(), "c:/RAMESH/fman_mainscreen.gif" );
v.insertElementAt( tempImage, numOfImages );
numOfImages++;
tempImage = getImage( getCodeBase(), "c:/RAMESH/mona.jpeg" );
v.insertElementAt( tempImage, numOfImages );
numOfImages++;
(HOW TO DO BUTTON OUT SIDE OF GIF IMAGE)
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;
repaint();
}
}

UBB code
Nathan Pruett
Bartender

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...
HTH,
-Nate
[This message has been edited by Nathan Pruett (edited April 04, 2001).]


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image+Button+applet