ibtn
import java.awt.*;
public class imagebtn extends Canvas
{
Image img;
public String name;
boolean press;
boolean onTop;
imagebtn(Image u,String s)
{
press=false;
onTop=false;
img=u;
name=s;
}
public void paint(Graphics g)
{
int[] ux={0,40,38,2, 2, 0,0};
int[] uy={0, 0, 2,2,38,40,0};
Polygon upEdge= new Polygon(ux,uy,7);
int[] dx={40,40,38,38, 2, 0,40};
int[] dy={40, 0, 2,38,38,40,40};
Polygon dnEdge= new Polygon(dx,dy,7);
if(onTop)
{
g.setFont(new Font("Times Roman",Font.PLAIN,9));
g.drawString(name,0,55);
}
g.setColor(Color.lightGray);
g.fillRect(0,0,40,40);
if((!press)&&onTop)
{
g.setColor(Color.white);
g.fillPolygon(upEdge);
g.setColor(Color.black);
g.fillPolygon(dnEdge);
}
if(press)
{
g.setColor(Color.black);
g.fillPolygon(upEdge);
g.setColor(Color.white);
g.fillPolygon(dnEdge);
press=!press;
}
g.drawImage(img,4,4,32,32,this);
}
public boolean mouseUp(Event e, int x, int y)
{
if((x>0)&&(x<40)&&(y>0)&&(y<40))
{
postEvent(new Event(this,Event.ACTION_EVENT,name));
press=true;repaint();return true;}
else {press=false;repaint();return false; }
}
public boolean mouseMove(Event e, int x, int y)
{
if((x>0)&&(x<40)&&(y>0)&&(y<40)){onTop=true;
repaint();}
else {onTop=false;repaint(); }
return false;
}
public boolean mouseExit(Event e, int x, int y)
{
onTop=false;repaint();
return false;
}
public Dimension minimumSize()
{
return new Dimension(40,55);
}
public Dimension preferedSize()
{
return minimumSize();
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|