import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.awt.geom.*; /*This is a basic class for a rectangular button button*/ public class ListenSquare { public double x,y,w,h; public int on; public Color C; /*square*/ public ListenSquare(double x,double y,double r,Color C) { this.x=x; this.y=y; this.C=C; this.w=r; this.h=r; this.on=0; } /*rectangle*/ public ListenSquare(double x,double y,double w,double h,Color C) { this.x=x; this.y=y; this.C=C; this.w=w; this.h=h; this.on=0; } public int inside(Point p) { int test=0; if((p.x>x)&&(p.xy)&&(p.y=1) g.setColor(CC); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(C); if(on!=0) g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void render(Graphics g,Color C1,Color C2) { if(on==0) g.setColor(C1); if(on!=0) g.setColor(C2); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(Color.black); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void render(Graphics g,Color C1,Color C2,Color C3) { if(on==0) g.setColor(C1); if(on!=0) g.setColor(C2); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(C3); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void infoRender(Graphics g) { g.setColor(new Color(0,0,0)); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setFont(new Font("Helvetica",Font.PLAIN,10)); g.drawString("?",(int)(x+4),(int)(y+10)); } /**These routines interact with the enhanced 2D graphics class*/ public void renderSmooth(Graphics2D g,Color CC) { Color C1,C2; C1=Color.black; if(on==1) C1=CC; C2=Color.white; mainRenderSmooth(g,C1,C2); } public void renderSmooth(Graphics2D g,Color CC1,Color CC2) { Color C1,C2; C1=Color.black; if(on!=0) C1=CC1; C2=CC2; mainRenderSmooth(g,C1,C2); } public void renderXLayer(Graphics2D g,Color C1,Color C2) { ListenSquare top=new ListenSquare(x,y,w/2,h,Color.white); ListenSquare bot=new ListenSquare(x+w/2,y,w/2,h,Color.white); top.mainRenderSmooth(g,C1,Color.black); bot.mainRenderSmooth(g,C2,Color.black); } public void renderYLayer(Graphics2D g,Color C1,Color C2) { ListenSquare top=new ListenSquare(x,y,w,h/2,Color.white); ListenSquare bot=new ListenSquare(x,y+h/2,w,h/2,Color.white); top.mainRenderSmooth(g,C1,Color.black); bot.mainRenderSmooth(g,C2,Color.black); } public void mainRenderSmooth(Graphics2D g,Color C1,Color C2,float f) { Polygon P=new Polygon(); float X[]={(float)(this.x),(float)(this.x+0),(float)(this.x+this.w),(float)(this.x+this.w)}; float Y[]={(float)(this.y),(float)(this.y+this.h),(float)(this.y+this.h),(float)(this.y+0)}; GeneralPath path=new GeneralPath(); path.moveTo(X[0],Y[0]); for(int i=1;i<4;++i) path.lineTo(X[i],Y[i]); path.closePath(); g.setColor(C1); g.fill(path); g.setColor(C2); g.setStroke(new BasicStroke(f)); g.draw(path); } public void mainRenderSmooth(Graphics2D g,Color C1,Color C2) { mainRenderSmooth(g,C1,C2,(float)(1.0)); } }