31 lines
687 B
Java
31 lines
687 B
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
|
|
public class MyFrame extends JFrame {
|
|
public MyFrame() {
|
|
// init frame
|
|
setSize(400, 300);
|
|
setTitle("MyFrame");
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setLayout(new BorderLayout());
|
|
|
|
// craete components
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
JButton button1 = new JButton("left");
|
|
JButton button2 = new JButton("right");
|
|
|
|
// set layout
|
|
panel.add(button1);
|
|
panel.add(button2);
|
|
add(panel, BorderLayout.PAGE_START);
|
|
|
|
// MyPanel object
|
|
MyPanel mp = new MyPanel(new FlowLayout(FlowLayout.CENTER));
|
|
add(mp, BorderLayout.CENTER);
|
|
|
|
// done
|
|
setVisible(true);
|
|
}
|
|
}
|