삼성SDS_멀티캠퍼스/Java

24일 차 Flow, Border, Grid Layout

박성우기 2015. 10. 13. 10:53
반응형

import java.awt.FlowLayout;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;


class Flow extends JFrame {


public Flow() {

this.setTitle("FlowLayoutTest");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel;


panel = new JPanel();

panel.setLayout(new FlowLayout(FlowLayout.CENTER));


panel.add(new JButton("Button1"));

panel.add(new JButton("Button2"));

panel.add(new JButton("Button3"));

panel.add(new JButton("B4"));

panel.add(new JButton("Long Button5"));


this.add(panel);


this.pack();

this.setVisible(true);

}


}
















import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

class Border extends JFrame {

public Border() {
this.setTitle("BorderLayout Test");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// 프레임은 디폴트로 BorderLayout이므로 사실 불필요하다
this.setLayout(new BorderLayout());

this.add(new JButton("Center"), BorderLayout.CENTER);
this.add(new JButton("Line Start"), BorderLayout.LINE_START);
this.add(new JButton("Line End"), BorderLayout.LINE_END);
this.add(new JButton("Page Start"), BorderLayout.PAGE_START);
this.add(new JButton("Page End"), BorderLayout.PAGE_END);

this.pack();
this.setVisible(true);
}
}





import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

class Grid extends JFrame {

public Grid() {

this.setTitle("Grid Layout");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLayout(new GridLayout(0, 3));
this.add(new JButton("Button1"));
this.add(new JButton("Button2"));
this.add(new JButton("Button3"));
this.add(new JButton("B4"));
this.add(new JButton("Long Button5"));
this.pack();
this.setVisible(true);
}
}







public class WookiLayout {

public static void main(String[] args) {

new Flow();

new Border();

new Grid();

}

}

















반응형