import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class MyFrame extends JFrame { public MyFrame() { this.setTitle("MyFrame Title"); this.setSize(400, 300); // Set the operation of the window when you click to close this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); BorderLayout fl = new BorderLayout(); // Set the layout manager for the frame. this.setLayout(fl); // The first panel JPanel jp = new JPanel(); this.add(jp, BorderLayout.PAGE_START); // The second panel MyPanel p = new MyPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton b1 = new JButton("Reset"); p.add(b1); JButton b2 = new JButton("right"); p.add(b2); b1.addMouseListener(new MouseAdapter() { @Override // use the button1 to reset public void mouseClicked(MouseEvent e) { p.cleanAllPoints(); } }); this.add(p, BorderLayout.CENTER); // Perform drawing and display to the desktop this.setVisible(true); } }