Witam, mam pewien problem, napisałem bardzo prosty program, który ma w wyświetlić 2 figury, chciałbym dodać tło, lecz nie działa.
Proszę o pomoc.
public class MyComponent extends JComponent {
public void paintComponent(Graphics g)
{
g.drawString("Witraj", 300, 75);
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rec = new Rectangle2D.Double(150,100 , 350, 350);
g2.setPaint(Color.BLUE);
g2.fill(rec);
Ellipse2D ellipse = new Ellipse2D.Double();
ellipse.setFrame(rec);
g2.setPaint(Color.RED);
g2.fill(ellipse);
g2.setPaint(new Color(66, 125, 17));
g2.drawString("Uwaga", 300, 500);
MyComponent p = new MyComponent();
p.setForeground(Color.WHITE);
p.setBackground(Color.BLACK);
}
}