CardLayoutDemo.java
Demo Card Layout v Javě
java
import javax.swing.*;
import javax.swing.border.*; // importováno kvůli rámu
import java.awt.*;
import java.awt.event.*; // importováno kvůli nastavení událostí
public class CardLayoutDemo extends JFrame {
private static final long serialVersionUID = 1L;
public static class Test {
public static void main(String[] args) {
JFrame f = new CardLayoutDemo("CardLayout");
}
}
GridBagConstraints g = new MyGridBagConstraints();
public CardLayoutDemo(String title) {
super(title);
setSize(400, 200);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
class MyGridBagConstraints extends GridBagConstraints {
private static final long serialVersionUID = 1L;
JButton c = new JButton("c");
JButton v = new JButton("v");
JButton b = new JButton("b");
JButton n = new JButton("n");
JButton m = new JButton("m");
JButton enter = new JButton("ENTER");
JButton alt = new JButton("alt");
JButton mezernik = new JButton("mezernik");
Container pane = getContentPane();
public MyGridBagConstraints() {
pane.setLayout(new GridBagLayout());
fill = HORIZONTAL;
gridx = 0;
gridy = 0;
pane.add(c, this);
fill = HORIZONTAL;
gridx = 1;
gridy = 0;
pane.add(v, this);
fill = HORIZONTAL;
gridx = 2;
gridy = 0;
pane.add(b, this);
fill = HORIZONTAL;
gridx = 3;
gridy = 0;
pane.add(n, this);
fill = HORIZONTAL;
gridx = 4;
gridy = 0;
pane.add(m, this);
fill = HORIZONTAL;
gridx = 5;
gridy = 0;
gridwidth = 2;
gridheight = 2;
ipadx = 30;
ipady = 30;
insets = new Insets(0,20,0,0);
pane.add(enter, this);
fill = HORIZONTAL;
gridx = 0;
gridy = 1;
insets = new Insets(0,0,0,0);
gridheight = 1;
gridwidth = 1;
ipadx = 0;
ipady = 0;
pane.add(alt, this);
fill = HORIZONTAL;
gridx = 1;
gridy = 1;
gridwidth = 5;
pane.add(mezernik, this);
}
}
}
Neformátovaný
Přidáno: 23.8.2013
Expirace: Neuvedeno