我有如下的定义, class ColorIcon implements Icon //
{
private Color fillColor;
private int w,h;
public ColorIcon (Color fillColor,int w, int h)
{
this.fillColor=fillColor;
this.w=w;
this.h=h;
}
public void paintIcon(Component c,Graphics g,int x,int y)
{
g.setColor(Color.black);
g.drawRect(x,y,this.w-1,this.h-1);
g.setColor(this.fillColor);
g.fillRect(x+1,y+1,this.w-2,this.h+2);
}
public int getIconWidth( )
{
return w;
}
public int getIconHeight()
{
return h;
}
}
//这是个启动的类
public class IconTest extends JFrame
{ public IconTest( )
{
Container contentPane=this.getContentPane();
ColorIcon red1=new ColorIcon(Color.red,50,50);
//在这里我如何可以在这个程序上画出red1来啊,}
问题是我该如何在应用程序中去画啊,
{
private Color fillColor;
private int w,h;
public ColorIcon (Color fillColor,int w, int h)
{
this.fillColor=fillColor;
this.w=w;
this.h=h;
}
public void paintIcon(Component c,Graphics g,int x,int y)
{
g.setColor(Color.black);
g.drawRect(x,y,this.w-1,this.h-1);
g.setColor(this.fillColor);
g.fillRect(x+1,y+1,this.w-2,this.h+2);
}
public int getIconWidth( )
{
return w;
}
public int getIconHeight()
{
return h;
}
}
//这是个启动的类
public class IconTest extends JFrame
{ public IconTest( )
{
Container contentPane=this.getContentPane();
ColorIcon red1=new ColorIcon(Color.red,50,50);
//在这里我如何可以在这个程序上画出red1来啊,}
问题是我该如何在应用程序中去画啊,
pack();
show();