public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.RED);
g2d.fillOval(0, 0, 30, 30);
g2d.drawOval(0, 50, 30, 30);
g2d.fillRect(50, 0, 30, 30);
g2d.drawRect(50, 50, 30, 30);
g2d.draw(new Ellipse2D.Double(0, 100, 30, 30));
}
Well, I am new to JPanel class and I have slight confusion. g is an object of Graphics class. So, what does (Graphics2D) g mean as in this line g seems as if it is a method and not an object? Further, can anyone tell me why Graphics2D class cannot be instantiated?