class MiniCalDay extends JButton {
private Color c;
MiniCalDay(String name, Color color) {
super(name);
this.c=color;
String thisObjectName = this.getClass().getCanonicalName();
setSize(settings.Size.CELL_SIZE);
setToolTipText(name);
setVerticalTextPosition(SwingConstants.CENTER);
setHorizontalTextPosition(SwingConstants.LEADING);
setBorderPainted(settings.getBorder(thisObjectName));
setBackground(settings.getBackround(thisObjectName));
setForeground(settings.getForeground(thisObjectName));
setFont(settings.getFont(thisObjectName));
}
@Override
public void paint(Graphics g) {
//draw triangle with color c ???
//how?
}
}
Thanx in advance!
> public void paint(Graphics g) {
Should be paintComponent(), for Swing classes
> //draw triangle with color c ???
> //how?
<http://java.sun.com/docs/books/tutorial/uiswing/painting/
practice.html>
> }
>
> }
Andrew T.
Thanx that helped a bit;
but now the problem is in this
public void paint(Graphics g) {
// TODO Auto-generated method stub
Graphics2D g2d = (Graphics2D)g;
super.paint(g);
Polygon p = new Polygon();
System.out.println(getBounds());
p.addPoint(getBounds().x+3, getBounds().y+3);
p.addPoint(getBounds().x+10, getBounds().y+3);
p.addPoint(getBounds().x+3, getBounds().x+10);
g2d.fillPolygon(p);
g2d.drawPolygon(p);
}
/* (non-Javadoc)
* @see java.awt.Component#getBounds()
*/
@Override
public Rectangle getBounds() {
// TODO Auto-generated method stub
return super.getBounds();
}
get bounds returns absolute position, but I would like to have relative
to by able to draw triangle..
>> }
>>
>> }
>
> Andrew T.
>
The relative origin position is (0,0). I.e. call addPoint(3,3), and
not addPoint(getBounds().x+3,getBounds().y+3).
- Oliver