package java0806;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFrame;
public class BorderLayoutEx extends JFrame {
public BorderLayoutEx() {
setTitle("BorderLayout 연습");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new BorderLayout(30, 20));
c.add(new JButton("계산하기"), BorderLayout.CENTER);
c.add(new JButton("덧셈"), BorderLayout.NORTH);
c.add(new JButton("뺄셈"), BorderLayout.SOUTH);
c.add(new JButton("곱셈"), BorderLayout.EAST);
c.add(new JButton("나눗셈"), BorderLayout.WEST);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new BorderLayoutEx();
}
}
package java0806;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class GridLayoutEx extends JFrame {
public GridLayoutEx() {
setTitle("GridLayout 연습");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(4, 2);
grid.setVgap(5);
Container c = getContentPane();
c.setLayout(grid);
c.add(new JLabel("이름"));
c.add(new JTextField(""));
c.add(new JLabel("이름"));
c.add(new JTextField(""));
c.add(new JLabel("이름"));
c.add(new JTextField(""));
c.add(new JLabel("이름"));
c.add(new JTextField(""));
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new GridLayoutEx();
}
}
package java0806;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class NullContainerEx extends JFrame {
public NullContainerEx() {
setTitle("Null Container 연습");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
JLabel la = new JLabel("안녕, 버튼을 누르세요!");
la.setLocation(130, 50); // 위치
la.setSize(200, 20); // 크기
c.add(la);
for (int i=0; i<=9; i++) {
JButton btn = new JButton(Integer.toString(i));
btn.setLocation(i*15, i*15);
btn.setSize(50, 20);
c.add(btn);
}
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new NullContainerEx();
}
}
'IT > Java' 카테고리의 다른 글
자바 마우스 이벤트, MouseListener, MouseAdapter (0) | 2018.08.07 |
---|---|
자바 이벤트 ActionListener, 독립클래스, 멤버내부클래스, 지역내부클래스, 익명클래스 (0) | 2018.08.07 |
자바 GUI, JFrame, FlowLayout (0) | 2018.08.06 |
자바 list안에 map 객체 넣기 (0) | 2018.08.06 |
자바 list를 이용한 student 데이터 관리(추가,중간삽입,삭제,전체출력) (0) | 2018.08.06 |