-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGridBagLayoutDemo.java
More file actions
54 lines (43 loc) · 1.36 KB
/
GridBagLayoutDemo.java
File metadata and controls
54 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import javax.swing.*;
import java.awt.*;
public class GridBagLayoutDemo extends JPanel{
private JButton newGame, setting, hiscore;
private ImageIcon titleImage;
private JLabel title;
private GridBagConstraints gbc = new GridBagConstraints();
public GridBagLayoutDemo() {
setLayout(new GridBagLayout());
gbc.insets = new Insets(5,5,5,5);
titleImage = new ImageIcon(getClass().getResource("title.png"));
title = new JLabel(titleImage);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
add(title,gbc);
newGame = new JButton("New Game");
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.BOTH;
add(newGame,gbc);
setting = new JButton("Setting");
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = 1;
add(setting,gbc);
hiscore = new JButton("High Score");
gbc.gridx = 1;
gbc.gridy = 3;
gbc.gridwidth = 1;
add(hiscore,gbc);
}
public static void main(String[] args){
GridBagLayoutDemo t = new GridBagLayoutDemo();
JFrame jf = new JFrame();
jf.setTitle("Tutorial");
jf.setSize(460,600);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.add(t);
}
}