Commit fda66b83 by Patryk Czarnik

layout managery

parent 892538de
package p30_swing.podstawy;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Okno3b {
public static void main(String[] args) {
JFrame frame = new JFrame("Nasza apka");
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label1 = new JLabel("Hello world");
label1.setHorizontalAlignment(JLabel.CENTER);
// label1.setVerticalAlignment(JLabel.TOP);
label1.setFont(new Font("Arial", Font.BOLD, 40));
label1.setForeground(Color.BLUE);
label1.setOpaque(true);
label1.setBackground(Color.YELLOW);
frame.add(label1);
// Domyślnym LayoutManagerem jest BorderLayout.
// On potrafi umieścić komponent w środku lub przy jednej z krawędzi określonej słowami "North", "South"...
JButton button1 = new JButton("Guzik 1");
button1.setFont(new Font("Arial", Font.BOLD, 32));
frame.add(button1, "North");
JButton button2 = new JButton("Guzik 2");
button2.setFont(new Font("Arial", Font.BOLD, 32));
frame.add(button2, "South");
frame.setVisible(true);
}
}
package p30_swing.podstawy;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.LayoutManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Okno3c_Border {
public static void main(String[] args) {
JFrame frame = new JFrame("Nasza apka");
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Tutaj BorderLayout wskazujemy jawnie. W parametrach można podać odstęp
// LayoutManager layout = new BorderLayout();
LayoutManager layout = new BorderLayout(10, 25);
frame.setLayout(layout);
JLabel label1 = new JLabel("Hello world");
label1.setHorizontalAlignment(JLabel.CENTER);
// label1.setVerticalAlignment(JLabel.TOP);
label1.setFont(new Font("Arial", Font.BOLD, 40));
label1.setForeground(Color.BLUE);
label1.setOpaque(true);
label1.setBackground(Color.YELLOW);
frame.add(label1);
JButton button1 = new JButton("Guzik 1");
button1.setFont(new Font("Arial", Font.BOLD, 32));
// frame.add(button1, "North");
frame.add(button1, BorderLayout.NORTH);
JButton button2 = new JButton("Guzik 2");
button2.setFont(new Font("Arial", Font.BOLD, 32));
frame.add(button2, BorderLayout.SOUTH);
frame.setVisible(true);
}
}
package p30_swing.podstawy;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.LayoutManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Okno3d_Flow {
public static void main(String[] args) {
JFrame frame = new JFrame("Nasza apka");
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// LayoutManager layout = new FlowLayout();
LayoutManager layout = new FlowLayout(FlowLayout.CENTER, 20, 10);
frame.setLayout(layout);
JLabel label1 = new JLabel("Hello world");
label1.setHorizontalAlignment(JLabel.CENTER);
// label1.setVerticalAlignment(JLabel.TOP);
label1.setFont(new Font("Arial", Font.BOLD, 40));
label1.setForeground(Color.BLUE);
label1.setOpaque(true);
label1.setBackground(Color.YELLOW);
frame.add(label1);
JLabel label2 = new JLabel("Ala ma kota");
label2.setFont(new Font("Arial", Font.BOLD, 40));
frame.add(label2);
JButton button1 = new JButton("Guzik 1");
button1.setFont(new Font("Arial", Font.BOLD, 32));
frame.add(button1);
JButton button2 = new JButton("Guzik 2");
button2.setFont(new Font("Arial", Font.BOLD, 32));
frame.add(button2);
frame.setVisible(true);
}
}
package p30_swing.podstawy;
import java.awt.Color;
import java.awt.Font;
import java.awt.LayoutManager;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Okno3e_Box {
// Tu używam już innego layoutu - BoxLayout
public static void main(String[] args) {
System.out.println("Początek main");
JFrame okno = new JFrame("Nasza apka");
okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okno.setSize(600, 400);
LayoutManager layout = new BoxLayout(okno.getContentPane(), BoxLayout.Y_AXIS);
okno.setLayout(layout);
JLabel label1 = new JLabel("Ala ma kota");
label1.setHorizontalAlignment(JLabel.CENTER);
label1.setFont(new Font("Arial", Font.BOLD, 30));
label1.setForeground(Color.RED);
okno.add(label1);
JLabel label2 = new JLabel("Ola ma psa");
label2.setHorizontalAlignment(JLabel.RIGHT);
label2.setFont(new Font("Arial", Font.ITALIC, 30));
label2.setForeground(Color.BLUE);
okno.add(label2);
JButton button1 = new JButton("Kliknij mnie");
button1.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 30));
button1.setForeground(Color.GREEN);
okno.add(button1);
okno.setVisible(true);
System.out.println("Koniec main");
}
}
package p30_swing.podstawy;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Okno3f_Grid {
public static void main(String[] args) {
System.out.println("Początek main");
JFrame okno = new JFrame("Nasza apka");
okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okno.setSize(600, 400);
LayoutManager layout = new GridLayout(2, 2);
okno.setLayout(layout);
JLabel label1 = new JLabel("Ala ma kota");
label1.setHorizontalAlignment(JLabel.CENTER);
label1.setFont(new Font("Arial", Font.BOLD, 30));
label1.setForeground(Color.RED);
okno.add(label1);
JLabel label2 = new JLabel("Ola ma psa");
label2.setHorizontalAlignment(JLabel.RIGHT);
label2.setFont(new Font("Arial", Font.ITALIC, 30));
label2.setForeground(Color.BLUE);
okno.add(label2);
JButton button1 = new JButton("Kliknij mnie");
button1.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 30));
button1.setForeground(Color.GREEN);
okno.add(button1);
JButton button2 = new JButton("Guzik 2");
button2.setFont(new Font("Arial", Font.BOLD, 30));
button2.setForeground(Color.MAGENTA);
okno.add(button2);
okno.setVisible(true);
System.out.println("Koniec main");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment