Skip to content

Instantly share code, notes, and snippets.

@astrophysik928
Created October 15, 2018 13:19
Show Gist options
  • Save astrophysik928/5be296a48818eaa302b59f21d1b55ac8 to your computer and use it in GitHub Desktop.
Save astrophysik928/5be296a48818eaa302b59f21d1b55ac8 to your computer and use it in GitHub Desktop.
JavaでGUI
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment