Java / GUI 프로그래밍 - 스윙(Swing)
Posted 2007/09/12 10:12, Filed under: 프로그래밍/Java
import javax.swing.*;
public class JFrameTest extends JFrame
{
public JFrameTest()
{
super("스윙 JFrame 테스트");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300,200);
setVisible(true);
}
public static void main(String args[])
{
JFrameTest jf = new JFrameTest();
}
}
import java.awt.*;
import javax.swing.*;
public class SixButtons extends JFrame
{
protected JButton one, two, three, four, five, six;
public SixButtons()
{
super("플로우 레이아웃");
getContentPane().setLayout(new FlowLayout());
one = new JButton("One");
two = new JButton("Two");
three = new JButton("Three");
four = new JButton("Four");
five = new JButton("Five");
six = new JButton("Six");
getContentPane().add(one);
getContentPane().add(two);
getContentPane().add(three);
getContentPane().add(four);
getContentPane().add(five);
getContentPane().add(six);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setVisible(true);
}
public static void main(String args[])
{
SixButtons sb = new SixButtons();
}
}
import java.awt.*;
import javax.swing.*;
public class FiveButtons extends JFrame
{
protected JButton b1, b2, b3, b4, b5;
public FiveButtons()
{
super("보더 레이아웃");
b1 = new JButton("Center");
b2 = new JButton("South");
b3 = new JButton("North");
b4 = new JButton("West");
b5 = new JButton("East");
getContentPane().add(b1, BorderLayout.CENTER);
getContentPane().add(b2, BorderLayout.SOUTH);
getContentPane().add(b3, BorderLayout.NORTH);
getContentPane().add(b4, BorderLayout.WEST);
getContentPane().add(b5, BorderLayout.EAST);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,200);
setVisible(true);
}
public static void main(String args[])
{
FiveButtons fb = new FiveButtons();
}
}
import java.awt.*;
import javax.swing.*;
public class FourButtons extends JFrame
{
protected JButton b1, b2, b3, b4;
public FourButtons()
{
super("그리드 레이아웃");
getContentPane().setLayout(new GridLayout(2,2));
b1 = new JButton("One");
b2 = new JButton("Two");
b3 = new JButton("Three");
b4 = new JButton("Four");
getContentPane().add(b1);
getContentPane().add(b2);
getContentPane().add(b3);
getContentPane().add(b4);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,200);
setVisible(true);
}
public static void main(String args[])
{
FourButtons fb = new FourButtons();
}
}
import java.awt.*;
import javax.swing.*;
public class SimpleGridBag extends JFrame {
JButton b1,b2,b3,b4,b5,b6;
public SimpleGridBag() {
super("SimpleGridBag");
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraint = new GridBagConstraints();
getContentPane().setLayout(gridbag);
constraint.fill = GridBagConstraints.BOTH;
constraint.weightx = 1.0;
constraint.weighty = 1.0;
b1 = new JButton("Button1");
gridbag.setConstraints(b1, constraint);
getContentPane().add(b1);
b2 = new JButton("Button2");
gridbag.setConstraints(b2, constraint);
getContentPane().add(b2);
constraint.gridwidth = GridBagConstraints.REMAINDER;
b3 = new JButton("Button3");
gridbag.setConstraints(b3, constraint);
getContentPane().add(b3);
constraint.gridwidth = 1;
constraint.gridheight = 2;
b4 = new JButton("Button4");
gridbag.setConstraints(b3, constraint);
getContentPane().add(b4);
constraint.gridwidth = GridBagConstraints.REMAINDER;
constraint.gridheight = 1;
constraint.weighty = 1.0;
b5 = new JButton("Button5");
gridbag.setConstraints(b5, constraint);
getContentPane().add(b5);
b6 = new JButton("Button6");
gridbag.setConstraints(b6, constraint);
getContentPane().add(b6);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,200);
setVisible(true);
}
public static void main(String args[])
{
new SimpleGridBag();
}
}
Response :
0 Trackback
,
0 Comment
Trackback URL : http://mysilpir.net/trackback/237



