import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.FlowLayout; 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("left"); p.add(b1); JButton b2 = new JButton("right"); p.add(b2); this.add(p, BorderLayout.CENTER); // Perform drawing and display to the desktop this.setVisible(true); } }