Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.GridLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- public class GUI extends JFrame {
- // コンテナに載せるボタンのための配列生成。
- JButton[] contena_button = new JButton[4];
- public static void main(String[] args) {
- new GUI();
- }
- GUI() {
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setSize(500, 500);
- this.setTitle("GUI");
- // コンテナのレイアウトを決める。2×2の区画
- this.getContentPane().setLayout(new GridLayout(2, 2));
- for (int i = 0; i < contena_button.length; i++) {
- // ボタンの値を代入。そのボタンをコンテナに置いていく
- contena_button[i] = new JButton(i + 1 + "月");
- this.getContentPane().add(contena_button[i]);
- }
- this.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment