반응형
import java.awt.Frame;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setVisible(true);
}
}
import java.awt.Frame;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setVisible(true);
}
}
public class FrameEx3 extends Frame {
public FrameEx3(){
this.setSize(400, 200);
this.setVisible(true);
}
}
public class FrameMain {
public static void main(String[] args){
FrameEx3 f1 = new FrameEx3();
}
}
import java.awt.Frame;
import java.awt.Toolkit;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
//스크린의 크기 재는 공식
Toolkit tk = Toolkit.getDefaultToolkit();
int x = tk.getScreenSize().width;
int y = tk.getScreenSize().height;
int locationX = x/2 - f1.getWidth()/2;
int locationY = y/2 - f1.getHeight()/2;
f1.setLocation(locationX, locationY);
f1.setVisible(true);
}
}
import java.awt.Frame;
import java.awt.Button;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setLocation(50, 50);
f1.add(new Button("난 버튼 1"), "Center");
f1.add(new Button("난 버튼 2"), "North");
f1.add(new Button("난 버튼 3"), "South");
f1.add(new Button("난 버튼 4"), "West");
f1.add(new Button("난 버튼 5"), "East");
f1.setVisible(true);
}
}
import java.awt.Frame;
import java.awt.Button;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setLocation(50, 50);
// f1.add(new Button("난 버튼 1"), "Center");
// f1.add(new Button("난 버튼 2"), "North");
// f1.add(new Button("난 버튼 3"), "South");
// f1.add(new Button("난 버튼 4"), "West");
// f1.add(new Button("난 버튼 5"), "East");
// f1.setLayout(new FlowLayout());
// f1.add(new Button("난 버튼 1"));
// f1.add(new Button("난 버튼 2"));
// f1.add(new Button("난 버튼 3"));
// f1.add(new Button("난 버튼 4"));
// f1.add(new Button("난 버튼 5"));
// f1.setLayout(new GridLayout(3, 2));
// f1.add(new Button("난 버튼 1"));
// f1.add(new Button("난 버튼 2"));
// f1.add(new Button("난 버튼 3"));
// f1.add(new Button("난 버튼 4"));
// f1.add(new Button("난 버튼 5"));
// f1.add(new Button("난 버튼 6"));
f1.setLayout(null);
Button btn1 = new Button("난 버튼 1");
btn1.setSize(100, 50);
btn1.setLocation(50, 50);
f1.add(btn1);
f1.setVisible(true);
}
}
import java.awt.*;
public class ChoiceEx1 extends Frame {
public static void main(String[] args){
ChoiceEx1 ce = new ChoiceEx1();
ce.setSize(300, 200);
ce.setLayout(null);
Choice c1 = new Choice();
c1.setSize(100, 50);
c1.setLocation(50, 50);
c1.add("월요일");
c1.add("화요일");
c1.add("수요일");
c1.add("목요일");
c1.add("금요일");
c1.add("토요일");
c1.add("일요일");
ce.add(c1);
ce.setVisible(true);
}
}
import java.awt.*;
public class ListEx1 extends Frame {
public static void main(String[] agrs){
ListEx1 le = new ListEx1();
//setSize, setLocation과 setBounds결과가 같다.
//le.setSize(300, 200);
//l1.setLocation(20,40);
le.setLayout(null);
//true설정시 다중선택 list(6)경우 단일 선택
List l1 = new List(6, true);
l1.setBounds(20, 40, 100, 120);
l1.setSize(100, 120);
l1.add("학생");
l1.add("선생");
l1.add("기사");
l1.add("프로그래머");
l1.add("회사원");
l1.add("음악가");
l1.add("감독");
le.add(l1);
le.setVisible(true);
}
}
import java.awt.*;
public class LabelTest {
public static void main(String[] args){
Frame f = new Frame("Login");
f.setSize(300, 200);
f.setLayout(null);
Label id = new Label("ID : "); //Label을 생성하고 크기와 위치를 지
id.setBounds(50, 50, 30, 10);// 50, 50위치에 크기가 가로 30, 세로 10
Label pwd = new Label("Password : ");
pwd.setBounds(50, 65, 100, 10);
//생성한 Label을 Frame에 포함시킨다.
f.add(id);
f.add(pwd);
f.setVisible(true);
}
}
import java.awt.*;
public class CheckboxEx1 extends Frame {
public static void main(String[] args){
CheckboxEx1 ce = new CheckboxEx1();
ce.setBounds(20, 20, 305, 250);
ce.setLayout(new FlowLayout());
//CheckBox
// Checkbox news = new Checkbox("news");
// Checkbox sports = new Checkbox("sports");
// Checkbox sports = new Checkbox("sports", true); //default 설정
// Checkbox movies = new Checkbox("movies");
// Checkbox music = new Checkbox("music");
//Radio Button
CheckboxGroup cg1 = new CheckboxGroup();
Checkbox news = new Checkbox("news", cg1, false);
Checkbox sports = new Checkbox("sports", cg1, true);
Checkbox movies = new Checkbox("movies", cg1, false);
Checkbox music = new Checkbox("music", cg1, false);
ce.add(news);
ce.add(sports);
ce.add(movies);
ce.add(music);
ce.setVisible(true);
}
}
import java.awt.Frame;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
public class TextFieldEx1 extends Frame{
public static void main(String[] arg){
TextFieldEx1 te = new TextFieldEx1();
te.setBounds(20, 20, 400, 65);
te.setLayout(new FlowLayout());
Label id = new Label("ID : ", Label.RIGHT);
Label pwd = new Label("Password : ", Label.RIGHT);
TextField txtId = new TextField(10);
TextField txtPwd = new TextField(10);
txtPwd.setEchoChar('*');
te.add(id);
te.add(txtId);
te.add(txtPwd);
te.setVisible(true);
}
}
import java.awt.*;
public class TextAreaEx1{
public static void main(String[] args){
Frame f = new Frame("Comments");
f.setSize(400, 220);
f.setLayout(new FlowLayout());
TextArea comments = new TextArea("하고 싶은 말을 적으세요. ", 10, 50);
f.add(comments);
comments.selectAll();
f.setVisible(true);
}
}
import java.awt.*;
public class ScrollbarTest {
public static void main(String[] args){
Frame f = new Frame("Scrollbar");
f.setSize(300, 200);
f.setLayout(null);
Scrollbar hor = new Scrollbar(Scrollbar.HORIZONTAL, 0, 50, 0, 100);
hor.setSize(100, 15);
hor.setLocation(60, 30);
Scrollbar ver = new Scrollbar(Scrollbar.VERTICAL, 50, 20, 0, 100);
ver.setSize(15, 100);
ver.setLocation(30, 30);
f.add(hor);
f.add(ver);
f.setVisible(true);
}
}
import java.awt.*;
public class PanelTest {
public static void main(String[] args){
Frame f = new Frame("Panel");
f.setSize(300, 200);
f.setLayout(null);//Frame이 Layout Manager를 사용하지 않도록 설정
Panel p = new Panel();
p.setBackground(Color.green);
p.setSize(100, 100);
p.setLocation(50, 50);
Button ok = new Button("Ok");
p.add(ok); //Button을 Panel에 포함
f.add(p); //Panel을 Frame에 포함
f.setVisible(true);
}
}
import java.awt.*;
public class MenuEx1 extends Frame{
public static void main(String[] args){
MenuEx1 me = new MenuEx1();
me.setBounds(30, 30, 640, 480);
MenuBar mb = new MenuBar();
Menu file = new Menu("파일");
MenuItem miNew = new MenuItem("새로 만들기");
MenuItem miOpen = new MenuItem("열기");
MenuItem miSave = new MenuItem("저장");
MenuItem miExit = new MenuItem("종료");
Menu print = new Menu("인쇄");
MenuItem miPrint = new MenuItem("인쇄");
MenuItem miPrintview = new MenuItem("인쇄 미리보기");
MenuItem miSetup = new MenuItem("설정");
//항목들을 print에 add함
print.add(miPrint);
print.add(miPrintview);
print.add(miSetup);
file.add(miNew);
file.add(miOpen);
file.add(miSave);
//print 붙여줌
file.addSeparator();
file.add(print);
//miExitn 붙여줌
file.addSeparator();
file.add(miExit);
Menu edit = new Menu("편집");
Menu view = new Menu("보기");
Menu help = new Menu("도움말");
mb.add(file);
mb.add(edit);
mb.add(view);
mb.add(help);
me.setMenuBar(mb);
me.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
public class CardLayoutTest {
public static void main(String[] args){
final Frame f = new Frame("CardLayoutTest");
final CardLayout card = new CardLayout(10, 10);
f.setLayout(card);
Panel card1 = new Panel();
card1.setBackground(Color.lightGray);
card1.add(new Label("Card 1"));
Panel card2 = new Panel();
card1.setBackground(Color.orange);
card1.add(new Label("Card 2"));
Panel card3 = new Panel();
card1.setBackground(Color.cyan);
card1.add(new Label("Card 3"));
f.add(card1, "1");
f.add(card1, "2");
f.add(card1, "3");
class Handler extends MouseAdapter{
public void mouseClicked(MouseEvent e){
//마우스 오른쪽 버튼을 눌렀을때
if(e.getModifiers() == e.BUTTON3_MASK){
card.previous(f);
}else{
card.next(f);
}
}
}
card1.addMouseListener(new Handler());
card2.addMouseListener(new Handler());
card3.addMouseListener(new Handler());
f.setSize(200,200);
f.setLocation(200, 200);
f.setVisible(true);
card.show(f,"1");
}
}
import java.awt.*;
import java.awt.event.*;
public class CheckboxEventTest2 extends Frame {
CheckboxGroup group;
Checkbox cb1;
Checkbox cb2;
Checkbox cb3;
CheckboxEventTest2(String title){
super(title);
group = new CheckboxGroup();
cb1 = new Checkbox("red", group, true);
cb2 = new Checkbox("green", group, false);
cb3 = new Checkbox("blue", group, false);
cb1.addItemListener(new EventHandler());
cb2.addItemListener(new EventHandler());
cb3.addItemListener(new EventHandler());
setLayout(new FlowLayout());
add(cb1);
add(cb2);
add(cb3);
setBackground(Color.red);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args){
CheckboxEventTest2 mainWin = new CheckboxEventTest2("CheckboxEventTest2");
}
class EventHandler implements ItemListener{
public void itemStateChanged(ItemEvent e){
Checkbox cb = (Checkbox)e.getSource();
String color = cb.getLabel();
if(color.equals("red")){
setBackground(Color.red);
}else if(color.equals("green")){
setBackground(Color.green);
}else{
setBackground(Color.blue);
}
}
}
}
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setVisible(true);
}
}
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setVisible(true);
}
}
public class FrameEx3 extends Frame {
public FrameEx3(){
this.setSize(400, 200);
this.setVisible(true);
}
}
public class FrameMain {
public static void main(String[] args){
FrameEx3 f1 = new FrameEx3();
}
}
import java.awt.Toolkit;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
//스크린의 크기 재는 공식
Toolkit tk = Toolkit.getDefaultToolkit();
int x = tk.getScreenSize().width;
int y = tk.getScreenSize().height;
int locationX = x/2 - f1.getWidth()/2;
int locationY = y/2 - f1.getHeight()/2;
f1.setLocation(locationX, locationY);
f1.setVisible(true);
}
}
import java.awt.Button;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setLocation(50, 50);
f1.add(new Button("난 버튼 1"), "Center");
f1.add(new Button("난 버튼 2"), "North");
f1.add(new Button("난 버튼 3"), "South");
f1.add(new Button("난 버튼 4"), "West");
f1.add(new Button("난 버튼 5"), "East");
f1.setVisible(true);
}
}
import java.awt.Button;
public class FrameEx2 extends Frame {
public static void main(String[] args){
FrameEx2 f1 = new FrameEx2();
f1.setSize(400, 200);
f1.setLocation(50, 50);
// f1.add(new Button("난 버튼 1"), "Center");
// f1.add(new Button("난 버튼 2"), "North");
// f1.add(new Button("난 버튼 3"), "South");
// f1.add(new Button("난 버튼 4"), "West");
// f1.add(new Button("난 버튼 5"), "East");
// f1.setLayout(new FlowLayout());
// f1.add(new Button("난 버튼 1"));
// f1.add(new Button("난 버튼 2"));
// f1.add(new Button("난 버튼 3"));
// f1.add(new Button("난 버튼 4"));
// f1.add(new Button("난 버튼 5"));
// f1.setLayout(new GridLayout(3, 2));
// f1.add(new Button("난 버튼 1"));
// f1.add(new Button("난 버튼 2"));
// f1.add(new Button("난 버튼 3"));
// f1.add(new Button("난 버튼 4"));
// f1.add(new Button("난 버튼 5"));
// f1.add(new Button("난 버튼 6"));
f1.setLayout(null);
Button btn1 = new Button("난 버튼 1");
btn1.setSize(100, 50);
btn1.setLocation(50, 50);
f1.add(btn1);
f1.setVisible(true);
}
}
public class ChoiceEx1 extends Frame {
public static void main(String[] args){
ChoiceEx1 ce = new ChoiceEx1();
ce.setSize(300, 200);
ce.setLayout(null);
Choice c1 = new Choice();
c1.setSize(100, 50);
c1.setLocation(50, 50);
c1.add("월요일");
c1.add("화요일");
c1.add("수요일");
c1.add("목요일");
c1.add("금요일");
c1.add("토요일");
c1.add("일요일");
ce.add(c1);
ce.setVisible(true);
}
}
public class ListEx1 extends Frame {
public static void main(String[] agrs){
ListEx1 le = new ListEx1();
//setSize, setLocation과 setBounds결과가 같다.
//le.setSize(300, 200);
//l1.setLocation(20,40);
le.setLayout(null);
//true설정시 다중선택 list(6)경우 단일 선택
List l1 = new List(6, true);
l1.setBounds(20, 40, 100, 120);
l1.setSize(100, 120);
l1.add("학생");
l1.add("선생");
l1.add("기사");
l1.add("프로그래머");
l1.add("회사원");
l1.add("음악가");
l1.add("감독");
le.add(l1);
le.setVisible(true);
}
}
public class LabelTest {
public static void main(String[] args){
Frame f = new Frame("Login");
f.setSize(300, 200);
f.setLayout(null);
Label id = new Label("ID : "); //Label을 생성하고 크기와 위치를 지
id.setBounds(50, 50, 30, 10);// 50, 50위치에 크기가 가로 30, 세로 10
Label pwd = new Label("Password : ");
pwd.setBounds(50, 65, 100, 10);
//생성한 Label을 Frame에 포함시킨다.
f.add(id);
f.add(pwd);
f.setVisible(true);
}
}
public class CheckboxEx1 extends Frame {
public static void main(String[] args){
CheckboxEx1 ce = new CheckboxEx1();
ce.setBounds(20, 20, 305, 250);
ce.setLayout(new FlowLayout());
//CheckBox
// Checkbox news = new Checkbox("news");
// Checkbox sports = new Checkbox("sports");
// Checkbox sports = new Checkbox("sports", true); //default 설정
// Checkbox movies = new Checkbox("movies");
// Checkbox music = new Checkbox("music");
//Radio Button
CheckboxGroup cg1 = new CheckboxGroup();
Checkbox news = new Checkbox("news", cg1, false);
Checkbox sports = new Checkbox("sports", cg1, true);
Checkbox movies = new Checkbox("movies", cg1, false);
Checkbox music = new Checkbox("music", cg1, false);
ce.add(news);
ce.add(sports);
ce.add(movies);
ce.add(music);
ce.setVisible(true);
}
}
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
public class TextFieldEx1 extends Frame{
public static void main(String[] arg){
TextFieldEx1 te = new TextFieldEx1();
te.setBounds(20, 20, 400, 65);
te.setLayout(new FlowLayout());
Label id = new Label("ID : ", Label.RIGHT);
Label pwd = new Label("Password : ", Label.RIGHT);
TextField txtId = new TextField(10);
TextField txtPwd = new TextField(10);
txtPwd.setEchoChar('*');
te.add(id);
te.add(txtId);
te.add(txtPwd);
te.setVisible(true);
}
}
public class TextAreaEx1{
public static void main(String[] args){
Frame f = new Frame("Comments");
f.setSize(400, 220);
f.setLayout(new FlowLayout());
TextArea comments = new TextArea("하고 싶은 말을 적으세요. ", 10, 50);
f.add(comments);
comments.selectAll();
f.setVisible(true);
}
}
public class ScrollbarTest {
public static void main(String[] args){
Frame f = new Frame("Scrollbar");
f.setSize(300, 200);
f.setLayout(null);
Scrollbar hor = new Scrollbar(Scrollbar.HORIZONTAL, 0, 50, 0, 100);
hor.setSize(100, 15);
hor.setLocation(60, 30);
Scrollbar ver = new Scrollbar(Scrollbar.VERTICAL, 50, 20, 0, 100);
ver.setSize(15, 100);
ver.setLocation(30, 30);
f.add(hor);
f.add(ver);
f.setVisible(true);
}
}
public class PanelTest {
public static void main(String[] args){
Frame f = new Frame("Panel");
f.setSize(300, 200);
f.setLayout(null);//Frame이 Layout Manager를 사용하지 않도록 설정
Panel p = new Panel();
p.setBackground(Color.green);
p.setSize(100, 100);
p.setLocation(50, 50);
Button ok = new Button("Ok");
p.add(ok); //Button을 Panel에 포함
f.add(p); //Panel을 Frame에 포함
f.setVisible(true);
}
}
public class MenuEx1 extends Frame{
public static void main(String[] args){
MenuEx1 me = new MenuEx1();
me.setBounds(30, 30, 640, 480);
MenuBar mb = new MenuBar();
Menu file = new Menu("파일");
MenuItem miNew = new MenuItem("새로 만들기");
MenuItem miOpen = new MenuItem("열기");
MenuItem miSave = new MenuItem("저장");
MenuItem miExit = new MenuItem("종료");
Menu print = new Menu("인쇄");
MenuItem miPrint = new MenuItem("인쇄");
MenuItem miPrintview = new MenuItem("인쇄 미리보기");
MenuItem miSetup = new MenuItem("설정");
//항목들을 print에 add함
print.add(miPrint);
print.add(miPrintview);
print.add(miSetup);
file.add(miNew);
file.add(miOpen);
file.add(miSave);
//print 붙여줌
file.addSeparator();
file.add(print);
//miExitn 붙여줌
file.addSeparator();
file.add(miExit);
Menu edit = new Menu("편집");
Menu view = new Menu("보기");
Menu help = new Menu("도움말");
mb.add(file);
mb.add(edit);
mb.add(view);
mb.add(help);
me.setMenuBar(mb);
me.setVisible(true);
}
}
import java.awt.event.*;
public class CardLayoutTest {
public static void main(String[] args){
final Frame f = new Frame("CardLayoutTest");
final CardLayout card = new CardLayout(10, 10);
f.setLayout(card);
Panel card1 = new Panel();
card1.setBackground(Color.lightGray);
card1.add(new Label("Card 1"));
Panel card2 = new Panel();
card1.setBackground(Color.orange);
card1.add(new Label("Card 2"));
Panel card3 = new Panel();
card1.setBackground(Color.cyan);
card1.add(new Label("Card 3"));
f.add(card1, "1");
f.add(card1, "2");
f.add(card1, "3");
class Handler extends MouseAdapter{
public void mouseClicked(MouseEvent e){
//마우스 오른쪽 버튼을 눌렀을때
if(e.getModifiers() == e.BUTTON3_MASK){
card.previous(f);
}else{
card.next(f);
}
}
}
card1.addMouseListener(new Handler());
card2.addMouseListener(new Handler());
card3.addMouseListener(new Handler());
f.setSize(200,200);
f.setLocation(200, 200);
f.setVisible(true);
card.show(f,"1");
}
}
import java.awt.event.*;
public class CheckboxEventTest2 extends Frame {
CheckboxGroup group;
Checkbox cb1;
Checkbox cb2;
Checkbox cb3;
CheckboxEventTest2(String title){
super(title);
group = new CheckboxGroup();
cb1 = new Checkbox("red", group, true);
cb2 = new Checkbox("green", group, false);
cb3 = new Checkbox("blue", group, false);
cb1.addItemListener(new EventHandler());
cb2.addItemListener(new EventHandler());
cb3.addItemListener(new EventHandler());
setLayout(new FlowLayout());
add(cb1);
add(cb2);
add(cb3);
setBackground(Color.red);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args){
CheckboxEventTest2 mainWin = new CheckboxEventTest2("CheckboxEventTest2");
}
class EventHandler implements ItemListener{
public void itemStateChanged(ItemEvent e){
Checkbox cb = (Checkbox)e.getSource();
String color = cb.getLabel();
if(color.equals("red")){
setBackground(Color.red);
}else if(color.equals("green")){
setBackground(Color.green);
}else{
setBackground(Color.blue);
}
}
}
}
반응형
'Study > Programming' 카테고리의 다른 글
AWT choice, list (0) | 2009.05.20 |
---|---|
AWT 주민등록번호 검사 (0) | 2009.05.19 |
자바 달력 (0) | 2009.05.18 |
자바 컬렉션 프레임워크 (0) | 2009.05.18 |
자바 예외처리 (0) | 2009.05.18 |