import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class GraphicsFunda extends JPanel implements ActionListener
{
Graphics myg;
JButton jb;
GraphicsFunda()
{
jb = new JButton("Draw");
add(jb);
setBackground(Color.YELLOW);
jb.addActionListener(this);
}
public void paintComponent(Graphics g)
{
myg=g;
g.drawOval(100,300,50,50);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jb)
myg.fillRect(10,10,200,200);
}
public static void main(String... sd)
{
GraphicsFunda gf = new GraphicsFunda();
JFrame jf = new JFrame();
jf.add(gf,BorderLayout.NORTH);
jf.setBackground(Color.blue);
jf.setSize(400,400);
jf.setVisible(true);
}
} Please Help me to solve the problem in it. If we take the reference of Graphics class from paintComponent, then can we use it in drawing other shapes, but it is not working here :(