Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with a class.

 
kotoisin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner in Java, and I am trying to make an exercise, where I am to make a class, -CoffeMug, which implements the interface Icon.
The class draws an Image of a CoffeeMug and fills it, by drawing and filling shapes.

import javax.swing.Icon;
import java.awt*;

public class CoffeeMug implements Icon
{
//constructs a coffeemug
private int width;
private int height;
private Color color;

public CoffeMug(int w, int h) {
width = w;
height = h;
color = Color.BLUE;
}
public int getIconWidth()
{
return width;
}

public int getIconHeight()
{
return width;
}

public void paintIcon(Component c, Graphics g, int x, int y)
{
Graphics2D g2 = (Graphics2D) g;
g2.setColor( color );
g2.fill( CoffeeMug );
}
}
I know it is SO wrong... But anyone have some advice for me?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic