0

am try to call paint in action perform but it not work

btnNewButton_5.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            class MyCanvas extends JComponent {

                public void paint(Graphics g) {
                    g.drawLine(10,20,50,60);
                }
            }


            JFrame window = new JFrame();
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            window.setBounds(30, 30, 300, 300);
            window.getContentPane().add(new MyCanvas());
            window.setVisible(true);

        }
    });

problem is it show only frame but rectangle doesn't draw

how can i edit this code help me

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
Par Whale
  • 23
  • 5

1 Answers1

0

First you should implement the paint() method on your class and then it is recall as simple function call use repaint() method on ActionListener.

Vinod Kumawat
  • 741
  • 5
  • 8