Guest User

Untitled

a guest
Oct 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.awt.GridLayout;
  2.  
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5.  
  6. public class GUI extends JFrame {
  7.  
  8. // コンテナに載せるボタンのための配列生成。
  9. JButton[] contena_button = new JButton[4];
  10.  
  11. public static void main(String[] args) {
  12.  
  13. new GUI();
  14.  
  15. }
  16.  
  17. GUI() {
  18.  
  19. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. this.setSize(500, 500);
  21. this.setTitle("GUI");
  22.  
  23. // コンテナのレイアウトを決める。2×2の区画
  24. this.getContentPane().setLayout(new GridLayout(2, 2));
  25.  
  26. for (int i = 0; i < contena_button.length; i++) {
  27.  
  28. // ボタンの値を代入。そのボタンをコンテナに置いていく
  29. contena_button[i] = new JButton(i + 1 + "月");
  30. this.getContentPane().add(contena_button[i]);
  31.  
  32. }
  33.  
  34. this.setVisible(true);
  35. }
  36. }
Add Comment
Please, Sign In to add comment