//앞의 내용의 컴포넌트 2개를 집어넣어서 함께 합치는 방법을 구현하라
import java.awt.*;
public class Exam21 extends Frame{
private Button bt = new Button("확인");
private Button bt1 = new Button("취소");
GridLayout gl = new GridLayout(1,2);
public Exam21(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(gl);
this.add(bt);
this.add(bt1);
}
public static void main(String[] ar) {
new Exam21("제목");
}
}
//앞의 내용의 컴포넌트 2개를 집어넣어서 함께 합치는 방법을 구현하라
import java.awt.*;
public class Exam21 extends Frame{
private Button bt = new Button("확인");
private Button bt1 = new Button("취소");
GridLayout gl = new GridLayout(1,2);
public Exam21(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(gl);
this.add(bt);
this.add(bt1);
}
public static void main(String[] ar) {
new Exam21("제목");
}
}
//페널에대한 설계를하는 프로그램.
import java.awt.*;
public class Exam22 extends Frame{
private Button bt = new Button("확인");
private Button bt1 = new Button("취소");
private Panel p = new Panel();
private BorderLayout bl = new BorderLayout();
private GridLayout gl = new GridLayout(1,2);
public Exam22(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(bl);//전체화면을 보더레이아웃을 선택한것임.
p.add(bt);
p.add(bt1);
this.add("South",p);
}
public static void main(String[] ar) {
new Exam22("제목");
}
}
//페널위에 페널을 이용하여 배치하는 프로그램.
import java.awt.*;
public class Exam23 extends Frame{
private Button yes_bt = new Button("확인");
private Button no1_bt = new Button("취소1");
private Button no2_bt = new Button("취소2");
private Panel p = new Panel();
private Panel p1 = new Panel();
private BorderLayout bl = new BorderLayout();
private GridLayout gl = new GridLayout(1,2);
private GridLayout gl1 = new GridLayout(2,1);
public Exam23(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(bl);
p.add(yes_bt);
p1.setLayout(gl1);
p1.add(no1_bt);
p1.add(no2_bt);
p.add(p1);
this.add("South",p);
}
public static void main(String[] ar) {
new Exam23("제목");
}
}
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.*;
public class Exam24 extends Frame{
public Exam24(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setBackground(Color.black);
this.setBackground(Color.RED);
}
public static void main(String[] ar) {
new Exam24("제목");
}
}
//자유로운 색상을 선택할 수 있도록...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exam25 extends Frame{
private Color cc = new Color(240,78,200);//자유자재로 색을 줌.
public Exam25(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setBackground(cc);
}
public static void main(String[] ar) {
new Exam25("제목");
}
}
//추가로 버튼이나 숫자에 색깔을 주는 방법.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Exam26 extends Frame{
private Color cc = new Color(123,77,3);
private Color cc1 = new Color(0,0,0);
private Color cc2 = new Color(255,0,0);
private Button bt = new Button("확인");
private GridLayout gl = new GridLayout();
public Exam26(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
this.init();
super.setSize(500,300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setBackground(cc);
this.setLayout(gl);
bt.setBackground(Color.orange);
bt.setBackground(cc1);
bt.setForeground(cc1);
this.add(bt);
}
public static void main(String[] ar) {
new Exam26("제목");
}
}
//GridBagLayout에 대한 구성프로그램.
import java.awt.*;
import javax.swing.*;
public class Exam27 extends JFrame{
private Button bt = new Button("AAA");
private GridBagLayout gbl = new GridBagLayout();
public Exam27(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
super.setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.init();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(gbl);
this.add(bt);
}
public static void main(String[] ar) {
new Exam27("제목");
}
}
//버튼과 레이블만으로 전화기구성을 만드는 프로그램.
import java.awt.*;
import javax.swing.*;
public class Exam28 extends JFrame{
private Label lb = new Label("전화기",Label.CENTER);
private Button[] bt = new Button[12];
private String[] str = new String[]{"*","0","#"};
//여기에 레이아웃을 정의하자
private BorderLayout bl = new BorderLayout(10,10);
private Panel p = new Panel();//가상영역의 공간배치를 위함.
private GridLayout gl = new GridLayout(4,3,5,5);
public Exam28(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
super.setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.init();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(bl);//(1)--전체 레이아웃 선정
this.add("North",lb);
p.setLayout(gl);//판넬의 레이아웃을 지정...(3)
for(int i=0; i<bt.length;++i) {
bt[i]=new Button(String.valueOf(i+1));//문자열로 바꾸기위한 명령어임.
if(i>=9) {
bt[i]=new Button(str[i-9]);
}
else {
bt[i]=new Button(String.valueOf(i+1));
}
p.add(bt[i]);
this.add("Center",p);//보더레이아웃에 올라가는 판넬내용 지정..(2)
}
}
public static void main(String[] ar) {
new Exam28("제목");
}
}
//체크박스와 체크박스그룹에 대한 예제임.
import java.awt.*;
import javax.swing.*;
public class Exam29 extends JFrame{
private Label lb = new Label("좋아하는 과일을 선택하시오?");//디폴트가 왼쪽정렬임.
private Checkbox a_cb = new Checkbox("사과");
private Checkbox b_cb = new Checkbox("딸기");
private Checkbox c_cb = new Checkbox("배");
private Label gel = new Label("당신의 성별은?");
private CheckboxGroup cg = new CheckboxGroup();//체크박스와 혼합하여 쓰면 자동으로 라디어버튼이됨.
private Checkbox m_cb=new Checkbox("남성",cg,true);
private Checkbox w_cb=new Checkbox("여성",cg,false);
//레이아웃 배치를 하고자 함.
private GridLayout gl = new GridLayout(4,1);
//라벨 1행과 2행의 내용은 판넬로 구성되어짐.
private Panel p = new Panel();
private GridLayout gl1 = new GridLayout(1,3);
private Panel p1 = new Panel();
private GridLayout gl2=new GridLayout(1,2);
public Exam29(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
super.setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.init();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(gl);//4행의 1열의 구성모습
this.add(lb);
p.setLayout(gl1);//1행의 3열
p.add(a_cb);
p.add(b_cb);
p.add(c_cb);
this.add(p);
this.add(gel);//성별을 묻는 내용라벨임.
p1.setLayout(gl2);//1행의 2열
p1.add(m_cb);
p1.add(w_cb);
this.add(p1);
}
public static void main(String[] ar) {
new Exam29("제목");
}
}
//초이스클래스와 초이스리스트에 따른 예제임.
import java.awt.*;
public class Exam30 extends Frame{
private Label blood_lb = new Label("혈액형은?");
private Choice blood_ch = new Choice();
private Label birth_lb = new Label("생년월일은?");
private Choice year_ch = new Choice();
private Label year_lb = new Label("년");
private Choice month_ch = new Choice();
private Label month_lb = new Label("월");
private Choice day_ch = new Choice();
private Label day_lb = new Label("일");
private Label alpha_lb = new Label("알파벳목록");
private List alpha_li = new List();
//내용구성은 모두 정의됨..화면의 구성레이아웃이 필요함.
private Panel p = new Panel();
private GridLayout gl = new GridLayout(4,1);
private Panel p1 = new Panel();
private GridBagLayout gb1 = new GridBagLayout();
private Panel p2 = new Panel();
private BorderLayout bl1 = new BorderLayout();
//전체레이아웃 자체를 보더레이아웃으로 선정함.
private BorderLayout bl = new BorderLayout();
public Exam30(String title) {
super(title);//super은 상위 생성자를 호출한다는 뜻이다.
super.setSize(500,300);
this.init();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = super.getSize();
int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
super.setLocation(xpos,ypos);
super.setResizable(false);
super.setVisible(true);
}
public void init() {
this.setLayout(bl);
//Data setting...
blood_ch.add("A형");
blood_ch.add("B형");
blood_ch.add("O형");
blood_ch.add("AB형");
for(int i=2021;i>1900;--i) {
year_ch.add(String.valueOf(i));
}
for(int i=1;i<=12;++i) {
month_ch.add(String.valueOf(i));
}
for(int i=1;i<=31;++i) {
day_ch.add(String.valueOf(i));
}
for(char i='A';i<='Z';++i) {
String s = ""+i+i+i;
alpha_li.add(s);
}
p.setLayout(gl);//4행1열 구성된 레이아웃임.
p1.setLayout(gb1);
p1.add(year_ch);
p1.add(year_lb);
p1.add(month_ch);
p1.add(month_lb);
p1.add(day_ch);
p1.add(day_lb);
p.add(blood_lb);
p.add(blood_ch);
p.add(birth_lb);
p.add(p1);
p.add(year_ch);
p.add(year_lb);
p.add(p1);
this.add("Center",p);
p2.setLayout(bl1);
p2.add("North",alpha_lb);
p2.add("Center",alpha_li);
this.add("East",p2);
}
public static void main(String[] ar) {
new Exam30("제목");
}
}