java.awt.Panel 컴포넌트
상속관계
java.lang.Object -> java.awt.Component -> java.awt.Container -> java.awt.Panel
예제1
import java.awt.*;
public class Round18_Ex01 {
public static void main(String[] ar) {
new Round18_Ex01_Sub();
}
class Round18_Ex01_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("Test");
public Round18_Ex01_Sub() {
super();
this.init();
this.start();
this.setSize(250, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
BorderLayout border = new BorderLayout();
this.setLayout(border);
lb.setBackground(Color.yellow);
this.add("South",lb);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
예제2
import java.awt.*;
public class Round18_Ex01 {
....
class Round18_Ex01_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("Test");
private Label lb1 = new Label("Test1");
public Round18_Ex01_Sub() {
....
}
public void init() {
BorderLayout border = new BorderLayout();
this.setLayout(border);
lb.setBackground(Color.yellow);
lb1.setBackground(Color.magenta);
GridLayout grid = new GridLayout(1, 2, 5, 5);
Panel p = new Panel();
p.setLayout(grid);
p.add(lb);
p.add(lb1);
this.add("South",p);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
예제3
import java.awt.*;
public class Round18_Ex01 {
....
class Round18_Ex01_Sub extends Frame {
....
public Round18_Ex01_Sub() {
....
}
public void init() {
BorderLayout border = new BorderLayout();
this.setLayout(border);
lb.setBackground(Color.yellow);
lb1.setBackground(Color.magenta);
lb2setBackground(Color.green);
GridLayout grid = new GridLayout(1, 2, 5, 5);
Panel p = new Panel(grid);
p.add(lb);
GridLayout grid1 = new GridLayout(2, 1, 5, 5);
Panel p1 = new Panel(grid1);
p1.add(lb1);
p1.add(lb2);
p.add(p1);
this.add("South",p);
}
....
}
}
AWT 전에 기억해야 할 클래스들
java.awt.Color
public void init() {
this.setBackground(Color.magenta);
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
lb.setBackground(Color.black);
lb.setForeground(Color.white);
this.add(lb);
}
Color color = new Color(int red, int green, int blue);
public void init() {
Color c1 = new Color(218, 185, 5);
Color c2 = new Color(117, 11, 213);
Color c3 = new Color(255, 255, 255);
this.setBackground(c1);
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
lb.setBackground(c2);
lb.setForeground(c3);
this.add(lb);
}
java.awt.Cursor
public void init() {
Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
Cursor cursor1 = new Cursor(Cursor.WAIT_CURSOR);
this.setCursor(cursor);
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
lb.setCurosr(cursor1);
lb.setBackground(Color.yellow);
this.add(lb);
}
java.awt.Dimension
- 스크린의 크기
- Dimension di = Toolkit.getDefaultToolkit().getScreenSize();
- 폭 : di.width 또는 di.getWidth()
- 높이: di.height 또는 di.getHeight()
- 프레임의 크기
- Frame f = new Frame();
- Dimension di = f.getSize();
- 폭 : di.width 또는 di.getWidth()
- 높이: di.height 또는 di.getHeight()
- 레이블의 크기
- Label lb = new Label();
- Dimension di = lb.getSize();
- 폭 : di.width 또는 di.getWidth()
- 높이: di.height 또는 di.getHeight()
java.awt.Font
public void init() {
Font font = new Font("SansSerif", Font.BOLD, 20);
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
lb.setFont(font);
lb.setBackground(Color.yellow);
this.add(lb);
}
java.awt.Image
- Image 객체
- Image image = Toolkit.getDefaultToolkit().getImage("c:\\test.gif");
public void init() {
this.setLayout(new FlowLayout());
lb.setBackground(Color.yellow);
this.add(lb);
this.setIconImage(Toolkit.getDefaultToolkit().getImage("c:\\abc.gif"));
}
java.awt.Insets
- Insets 클래스의 객체생성
- Insets inset = new Insets(int 위쪽_여백, int 좌측_여백, int 아래쪽_여백, int 우측_여백);
java.awt.Toolkit
- 화면의 크기를 얻어내는 클래스 : Toolkit.getDefaultToolkit().getScreenSize()
- 로컬 경로 이미지를 얻어내는 클래스 : Toolkit.getDefaultToolkit().getImage("로컬경로파일")
AWT 컴포넌트
java.awt.Label
java.lang.Object -> java.awt.Component -> java.awt.Label
import java.awt.*;
public class Round18_Ex06 {
public static void main(String[] ar) {
new Round18_Ex06_Sub();
}
class Round18_Ex06_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("최초문자(좌측정렬) -> ", Label.LEFT);
public Round18_Ex06_Sub() {
super();
this.init();
this.start();
this.setSize(500, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch( InterruptedException e) {}
String str = lb.getText().trim();
lb.setAlignment(Label.CENTER);
lb.setText(str + "다음정렬(중앙정렬) ->");
try { Thread.sleep(5000); } catch( InterruptedException e) {}
String str = lb.getText().trim();
lb.setAlignment(Label.RIGHT);
lb.setText(str + "다음정렬(우측정렬) ->");
}
public void init() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(gridbag);
lb.setBackground(Color.yellow);
gc.fill = GridBagConstraints.HORIZONTAL;
gc.weightx = 1;
gridbag.setConstraingts(lb, gc);
this.add(lb);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.Button
java.lang.Object -> java.awt.Component -> java.awt.Button
import java.awt.*;
public class Round18_Ex07 {
public static void main(String[] ar) {
new Round18_Ex07_Sub();
}
class Round18_Ex07_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Button[] bt = new Button[12];
public Round18_Ex07_Sub() {
super();
this.init();
this.start();
this.setSize(300, 400);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
CardLayout card = new CardLayout(5, 5);
this.setLayout(card); // 주변 둘레(가장자리) 여백 때문에 설정
Panel p = new Panel(new GridLayout(4, 3, 5, 5));
Font font = new Font("TimesRoman", Font.BOLD, 20);
Font font1 = new Font("SansSerif", Font.BOLD, 20);
String[] str = {"*","0","#"};
for(int i=0; i < bt.length; i++) {
if(i < 9) {
bt[i] = new Button(String.valueOf(i + 1));
bt[i].setFont(font);
} else {
bt[i] = new Button(str[i-9]);
bt[i].setFont(font1);
}
}
this.add("view",p);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.Checkbox
java.lang.Object -> java.awt.Component -> java.awt.Checkbox
import java.awt.*;
public class Round18_Ex08 {
public static void main(String[] ar) {
new Round18_Ex08_Sub();
}
class Round18_Ex08_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("좋아하는 과일을 모두 체크하세요!");
private List<Checkbox> cbs = Arrays.asList(
new CheckBox("사과")
, new CheckBox("딸기", false)
, new CheckBox("키위", true)
, new CheckBox("포도")
);
private List<Button> bts = Arrays.asList(
new Button("확인")
, new Button("취소")
);
public Round18_Ex08_Sub() {
super("선택");
this.init();
this.start();
this.setSize(300, 400);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
BorderLayout border = new BorderLayout();
this.setLayout(border);
this.add("North",lb);
Panel p = new Panel(new GridLayout(2,2));
for(Checkbox cb : cbs) {
p.add(cb);
}
this.add("Center",p);
Panel p1 = new Panel(new FlowLayout(FlowLayout.RIGHT));
for(Button bt : bts) {
p1.add(bt);
}
this.add("South", p1);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.CheckboxGroup
java.lang.Object -> java.awt.CheckboxGroup
import java.awt.*;
public class Round18_Ex08 {
public static void main(String[] ar) {
new Round18_Ex08_Sub();
}
class Round18_Ex08_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("좋아하는 과일을 모두 체크하세요!");
privaet CheckboxGroup cg = new CheckboxGroup();
private List<Checkbox> cbs = Arrays.asList(
new CheckBox("사과", false, cg)
, new CheckBox("딸기", false, cg)
, new CheckBox("키위", true, cg)
, new CheckBox("포도", false, cg)
);
private List<Button> bts = Arrays.asList(
new Button("확인")
, new Button("취소")
);
public Round18_Ex08_Sub() {
....
}
public void init() {
....
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.Choice
java.lang.Object -> java.awt.Component -> java.awt.Choice
import java.awt.*;
public class Round18_Ex09 {
public static void main(String[] ar) {
new Round18_Ex09_Sub();
}
class Round18_Ex09_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private List<Label> lbs = Arrays.asList(
new Label("생년월일 : ",Label.LEFT)
, new Label("년 ",Label.LEFT)
, new Label("월 ",Label.LEFT)
, new Label("일 ",Label.LEFT)
);
private List<Choice> choices = Arrays.asList(
new Choice()
, new Choice()
, new Choice()
);
public Round18_Ex09_Sub() {
super("선택");
this.init();
this.start();
this.setSize(300, 400);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
choices.get(0).select("1980");
choices.get(1).select("12");
choices.get(2).select("25");
choices.get(2).requestFocus();
}
public void init() {
for(int i = 2004; i >= 1970; i--) {
choices.get(0).add(String.valueOf(i));
}
for(int i = 1 i <= 12; i++) {
choices.get(1).add(String.valueOf(i));
}
for(int i = 1 i <= 31; i++) {
choices.get(2).add(String.valueOf(i));
}
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(gridgag);
for(int i=0; i<lbs.size(); i++){
if(i > 0){
gridbag.setConstraints(choices.get(i-1), gc);
this.add(choices.get(i-1));
}
gridbag.setConstraints(lbs.get(i), gc);
this.add(lbs.get(i));
}
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.List
java.lang.Object -> java.awt.Component -> java.awt.List
import java.awt.*;
public class Round18_Ex10 {
public static void main(String[] ar) {
new Round18_Ex10_Sub();
}
class Round18_Ex10_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private java.util.List<Button> bts = Arrays.asList(
new Button("-->")
, new Button("<--")
);
private java.util.List<List> lists = Arrays.asList(
new List(10, true)
, new List(10)
);
public Round18_Ex10_Sub() {
super("목록 선택");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
lists.get(0).select(2);
lists.get(0).select(2);
lists.get(0).select(2);
lists.get(0).select(2);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
String[] str = lists.get(0).getSelectedItems();
for(int i = 0; i < str.length; i++) {
list.get(1).add(str[i]);
}
try { Thread.sleep(5000); } catch(InterruptedException e) {}
lists.get(0).deselect(2);
lists.get(0).deselect(2);
lists.get(0).deselect(2);
lists.get(0).deselect(2);
}
public void init() {
for(int = 0; i < 20; i++) {
lists.get(0).add("TEST " + (i+1));
}
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(gridgag);
gc.insets = new Insets(0, 0, 0, 10);
gridbag.setConstraints(lists.get(0), gc);
this.add(lists.get(0));
GridLayout grid = new GridLayout(2, 1, 0, 20);
Panel p = new Panel(grid);
for(Button bt : bts){
p.add(bt);
}
gc.insets = new Insets(0, 0, 0, 0);
gridbag.setConstraints(p, gc);
this.add(p);
gc.insets = new Insets(0, 10, 0, 0);
gridbag.setConstraints(lists.get(1), gc);
this.add(lists.get(1));
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.TextComponent
java.lang.Object -> java.awt.Component -> java.awt.TextComponent
java.awt.TextField
java.lang.Object -> java.awt.Component -> java.awt.TextComponent -> java.awt.TextField
import java.awt.*;
public class Round18_Ex11 {
public static void main(String[] ar) {
new Round18_Ex11_Sub();
}
class Round18_Ex11_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("문자열 입력 : ", Label.RIGHT);
private TextField tf = new TextField(30);
public Round18_Ex11_Sub() {
super("문자열");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
String str = tf.getText().trim();
tf.setEchoChar((char)0);
tf.setText(str);
}
public void init() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(gridgag);
gc.fill = GridBagConstraints.HORIZONTAL;
gc.weight = 4;
gridbag.setConstraints(lb, gc);
this.add(lb);
gc.weightx = 6;
gridbag.setConstraints(tf, gc);
this.add(tf);
tf.setEchoChar('*');
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.TextArea
java.lang.Object -> java.awt.Component -> java.awt.TextComponent -> java.awt.TextArea
import java.awt.*;
public class Round18_Ex12 {
public static void main(String[] ar) {
new Round18_Ex12_Sub();
}
class Round18_Ex12_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("5초 이내에 특정 내용의 범위를 지정하시오!");
private Label lb1 = new Label("선택된 내용 : ", Label.RIGHT);
private TextArea ta = new TextArea("abcdefghijk\nlmnopqrs\ntuvwxyz\n");
private TextField tf = new TextField();
public Round18_Ex12_Sub() {
super("문자열");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 = dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
String str = ta.getSelectedText().trim();
int start = ta.getSelectionStart();
int end = ta.getSelectionEnd();
tf.setText(str);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
ta.replaceRange("",start, end);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
str = tf.getText().trim();
int length = ta.getText().trim().length();
ta.setCaretPosition(length);
ta.append(str);
}
public void init() {
BorderLayout border = new BorderLayout(5, 5);
this.setLayout(border);
this.add("North",lb);
this.add("Center",ta);
BorderLayout border1 = new BorderLayout(3, 3);
Panel p = new Panel(border1);
p.add("West",lb1);
p.add("Center",tf);
this.add("South",p);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.Dialog
java.lang.Object -> java.awt.Component -> java.awt.Container -> java.awt.Window -> java.awt.Dialog
import java.awt.*;
public class Round18_Ex13 {
public static void main(String[] args) {
new Round18_Ex13_Sub();
}
class Round18_Ex13_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Dialog dlg = new Dialog(this,"종속된 Dlg1", false);
private Label dlglb = new Label("종속된 Dlg1 이다.", Label.CENTER);
private Dialog dlg1 = new Dialog(this, "종속된 Dlg2", false);
private Label dlg1lb = new Label("종속된 Dlg2 이다.", Label.CENTER);
public Round18_Ex13_Sub() {
super("최상위 Frame!!");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch( InterruptedException e ) {}
dlg.setVisible(true);
try { Thread.sleep(5000); } catch( InterruptedException e ) {}
dlg.setVisible(false);
dlg1.setVisible(true);
try { Thread.sleep(5000); } catch( InterruptedException e ) {}
dlg1.setVisible(false);
}
public void init() {
Dimension dimen0 = Toolkit.getDefaultToolkit().getScreenSize();
BorderLayout border = new BorderLayuout();
dlg.setLayuout(border);
dlg.add("Center",dlglb);
dlg.setSize(150, 120);
Dimension dimen2 = dlg.getSize();
int xpos1 = (int)(dimen0.getWidth()/2 - dimen2.getWidth()/2);
int ypos1 = (int)(dimen0.getHeight()/2 - dimen2.getHeight()/2);
dlg.setLocation(xpos1, ypos1);
BorderLayout border1 = new BorderLayout();
dlg1.setLayout(border1);
dlg1.add("Center",dlg1lb);
dlg1.setSize(150,120);
Dimension dimen3 = dlg1.getSize();
int xpos2 = (int)(dimen0.getWidth()/2 - dimen3.getWidth()/2);
int ypos2 = (int)(dimen0.getHeight()/2 - dimen3.getHeight()/2);
dlg.setLocation(xpos2, ypos2);
}
public void start() {
}
}
}
java.awt.FileDialog
java.lang.Object -> java.awt.Component -> java.awt.Container -> java.awt.Window -> java.awt.Dialog -> java.awt.FileDialog
import java.awt.*;
public class Round18_Ex14 {
public static void main(String[] args) {
new Round18_Ex14_Sub();
}
class Round18_Ex14_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("directory = ");
private Label lb1 = new Label("file = ");
private FileDialog fdlg = new FileDialog(this, "내파일열기", FileDialog.LOAD);
public Round18_Ex14_Sub() {
super("파일 다이얼로그");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch( InterruptedException e ) {}
fdlg.setVisible(true);
String dir = fdlg.getDirectory();
String file = fdlg.getFile();
lb.setText(lb.getText().trim() + dir);
lb1.setText(lb1.getText().trim() + file);
}
public void init() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
this.setLayout(gridbag);
lb.setBackground(Color.yellow);
lb1.setBackground(Color.yellow);
gc.weightx = 1;
gc.fill = GridBagConstrants.HORIZONTAL;
gc.gridwidth = GridBagConstrants.REMAINDER;
gc.insets = new Insets(0, 0, 10, 0);
gridgag.setConstrants(lb, gc);
this.add(lb);
gridbag.setConstrants(lb1, gc);
this.add(lb1);
}
public void start() {
}
}
}
java.awt.MenuBar
java.lang.Object -> java.awt.Component -> java.awt.MenuBar
java.awt.Menu
java.lang.Object -> java.awt.Component -> java.awt.MenuItem -> java.awt.Menu
import java.awt.*;
public class Round18_Ex15 {
public static void main(String[] ar) {
new Round18_Ex15_Sub();
}
class Round18_Ex015Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private MenuBar mb = new MenuBar();
private List<Menu> ms = Arrays.asList(
new Menu("파일")
, new Menu("편집")
, new Menu("보기")
, new Menu("도움말")
);
public Round18_Ex15_Sub() {
super("메뉴 만들기");
this.init();
this.start();
this.setSize(250, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
this.setMenuBar(mb);
for(Menu m : ms) {
mb.add(m);
}
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.MenuItem
java.lang.Object -> java.awt.Component -> java.awt.MenuItem
java.awt.CheckboxMenuItem
java.lang.Object -> java.awt.Component -> java.awt.MenuItem -> java.awt.CheckboxMenuItem
import java.awt.*;
public class Round18_Ex15 {
public static void main(String[] ar) {
new Round18_Ex15_Sub();
}
class Round18_Ex015Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private MenuBar mb = new MenuBar();
private List<Menu> ms = Arrays.asList(
new Menu("파일")
, new Menu("편집")
, new Menu("보기")
, new Menu("도움말")
);
private List<MenuItem> file = Arrays.asList(
new MenuItem("새파일")
,new MenuItem("열기")
,new MenuItem("저장")
,new MenuItem("다른 이름으로 저장")
,new MenuItem("종료")
);
private List<MenuItem> edit = Arrays.asList(
new MenuItem("찾기")
,new MenuItem("바꾸기")
,new MenuItem("이동")
);
private List<Menu> view = Arrays.asList(
new Menu("모양")
,new Menu("도구모음")
);
private List<MenuItem> vmo = Arrays.asList(
new MenuItem("기본모양")
,new MenuItem("웹모양")
,new MenuItem("인쇄모양")
);
private List<CheckboxMenuItem> vtool = Arrays.asList(
new CheckboxMenuItem("표준", true)
, new CheckboxMenuItem("서식", true)
, new CheckboxMenuItem("검토", false)
);
private List<MenuItem> help = Arrays.asList(
new MenuItem("버젼정보")
);
public Round18_Ex15_Sub() {
super("메뉴 만들기");
this.init();
this.start();
this.setSize(250, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
this.setMenuBar(mb);
for(Menu m : ms) {
mb.add(m);
}
//파일
for(MenuItem mi: file) {
ms.get(0).add(mi);
}
//편집
for(MenuItem mi: edit) {
ms.get(1).add(mi);
}
//보기
for(Menu m: view) {
ms.get(2).add(m);
}
//도움말
for(MenuItem mi: help){
ms.get(3).add(mi);
}
//모양
for(MenuItem mi: vmo){
view.get(0).add(mi);
}
//도구모음
for(CheckboxMenuItem cmi: vtool){
view.get(1).add(cmi);
}
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.ScrollPane
java.lang.Object -> java.awt.Component -> java.awt.Container -> java.awt.ScrollPane
import java.awt.*;
public class Round18_Ex16 {
public static void main(String[] ar) {
new Round18_Ex16_Sub();
}
class Round18_Ex16_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private Label lb = new Label("많은 버튼들 추가...");
private Button[] bt = new Button[50];
private Button bt1 = new Button("확인");
private Button bt2 = new Button("취소");
public Round18_Ex16_Sub() {
super("Scroll Pane!");
this.init();
this.start();
this.setSize(300, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}
public void init() {
BorderLayout border = new BorderLayout(5, 5);
this.setLayout(border);
this.add("North",lb);
GridLayout grid = new GridLayout(10, 5, 2, 2);
Panel p = new Panel(grid);
for(int i=0; i < bt.length; i++) {
bt[i] = new Button("TEST " + i);
p.add(bt[i]);
}
//this.add("Center",p);
ScrollPane sp = new ScrollPane();
sp.add(p);
this.add("Center",sp);
FlowLayout flow1 = new FlowLayout(FlowLayout.RIGHT);
Pane p1 = new Panel(flow1);
p1.add(bt1);
p1.add(bt2);
this.add("South", p1);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
java.awt.PopupMenu
java.lang.Object -> java.awt.Component -> java.awt.MenuItem ->java.awt.Menu -> java.awt.PopupMenu
import java.awt.*;
public class Round18_Ex17 {
public static void main(String[] ar) {
new Round18_Ex17_Sub();
}
class Round18_Ex17_Sub extends Frame {
private Dimension dimen, dimen1;
private int xpos, ypos;
private PopupMenu pm = new PopupMenu("5초후 나타난다.");
private List<MenuItem> mis = Arrays.asList(
new MenuItem("복사")
, new MenuItem("잘라내기")
, new MenuItem("붙여넣기")
);
private Menu align = new Menu("정렬");
private List<CheckboxMenuItem> aligns = Arrays.asList(
new CheckboxMenuItem("크기순", false)
, new CheckboxMenuItem("이름순", false)
, new CheckboxMenuItem("자동정렬", true)
);
public Round18_Ex17_Sub() {
super();
this.init();
this.start();
this.setSize(250, 200);
dimen = Toolkit.getDefaultToolkit().getScreenSize();
dimen1 = this.getSize();
xpos = (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
this.setLocation(xpos, ypos);
this.setVisible(true);
try { Thread.sleep(5000); } catch(InterruptedException e) {}
pm.show(ta, 50, 0);
}
public void init() {
BorderLayout border = new BorderLayout();
this.setLayout(border);
this.add("Center",ta);
for(MenuItem mi : mis) {
pm.add(mi);
}
pm.addSeparator();
for(int i=0; i< aligns.size(); i++) {
align.add(aligns.get(i));
if(i == 1 ) {
align.addSeparator();
}
}
pm.add(align);
ta.add(pm);
}
public void start() {
// Event나 쓰레드 처리할 부분
}
}
}
과제
과제1. 자바 폼을 이용하여 로그인 폼 만들기
과제2. 자바 폼을 이용하여 계산기 폼 만들기