GameWindow.java
Použití GridBagLayout
java
package thecode;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GameWindow extends JFrame {
private static final long serialVersionUID = 1L;
private JButton tl1 = new MyButton("Start");
private JButton tl2 = new MyButton("Návod");
public static void main(String[] args) {
GameWindow okno = new GameWindow("Nim-The Game");
}
public GameWindow(String title) {
super(title);
setSize(800, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
Container kontej = getContentPane();
GridBagLayout srg = new GridBagLayout();
kontej.setLayout(srg);
kontej.add(tl1, new Gbc(1, 0));
kontej.add(tl2, new Gbc(1, 1));
setContentPane(kontej);
}
class MyButton extends JButton {
private static final long serialVersionUID = 1L;
MyButton(final String title) {
super(title);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Tlačítko " + title);
}
});
}
}
class Gbc extends GridBagConstraints {
private static final long serialVersionUID = 1L;
Gbc(int gridx, int gridy) {
this.gridx = gridx;
this.gridy = gridy;
}
}
}
Neformátovaný
Přidáno: 15.12.2013
Expirace: Neuvedeno