dimanche 29 mars 2015

Using Icon and myIcon



I am practicing using Icon and myIcon and am getting an error saying that myIcon must be defined in its own file. I am pretty sure I defined it within the code and am confused what I did wrong.



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

public class TestIcon {
public static void main(String[] args) {
myIcon icn = new myIcon(40,50);
JOptionPane.showMessageDialog(null, "Hello World!", "Message", JOptionPane.INFORMATION_MESSAGE, icn);
}
}

public class myIcon implements Icon{
private int width;
private int height;

public myIcon(int width, int height) {
this.width=width;
this.height=height;
}
public int getIconWidth(){
return width;
}
public int getIconHeight(){
return height;
}
public void paintIcon(Component c, Graphics g, int x, int y){
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double ellipse = new Ellipse2D.Double(x,y,width, height);

g2.setColor(Color.RED);
g2.fill(ellipse);
}
}



Aucun commentaire:

Enregistrer un commentaire