Choice/ List / TextField / TextArea ,Layout, Menu

|

-- Choice/ List / TextField / TextArea --

import java.awt.*;

class Comp283
{
    public static void main(String[] args)
    {
        Frame f = new Frame();

        f.setLayout(new FlowLayout());
       
        Choice c = new Choice();                     //Choice생성
        List l = new List(3,false);                      //List생성
        TextField t = new TextField("lee",20);       //TextField생성
        TextArea ta = new TextArea(5,50);           //TdxtArea생성

 

        Scrollbar sbar = new Scrollbar(Scrollbar.HORIZONTAL,50,0,1,300);

 

        c.add("rad");
        c.add("green");
        c.add("blue");
        l.add("rad");
        l.add("green");
        l.add("blue");                      //컨트롤에 아이템추가
 
        t.setText("samp");               //TextField에 문자 등록
        String str = t.getText();        //TextField에서 문자 가져와서 str변수에 넣기

        ta.setText(str);                   //TextArea에 str변수의 문자열 등록

       

        f.add(c);
        f.add(l);
        f.add(t);
        f.add(ta);
        f.add(sbar);                      // Frame에 컨트롤 붙이기

       

        f.setSize(500,500);
        f.setVisible(true);
    }
}


 

------------ CANVAS ------------


import java.awt.*;

class Canv
{

 public static void main(String[] args)
 {
  Frame f = new Frame();

 

  Canvas ca = new Canvas();                       // 캔버스 생성
  ca.setBackground(new Color(255,255,0));     // 캔버스 색깔 지정
  ca.setSize(200,200);                                 // 사이즈 지정
 
  f.add(ca);                                               // 프레임에 캔버스 붙이기


  f.setVisible(true);
  f.setSize(300,300);
 }
}


 

------------ PANEL ------------


import java.awt.*;

class Pt
{
 public static void main(String[] args)
 {
  Frame f = new Frame();
  f.setLayout(new FlowLayout());

 

  Panel p = new Panel();                     // 패널 생성
 
  Button b1 = new Button("b1");            // 버튼생성
  Button b2 = new Button("b2");
  Button b3 = new Button("b3");
 
  p.setBackground(Color.blue);            // 패널 배경색 지정


  p.add(b1); p.add(b2);                      // 패널에 버튼 붙이기

  f.add(p);                                       // 프레임에 패널 붙이기

  f.add(b3);

 

  f.setSize(300,200);
  f.setVisible(true);
 }
}
 
 

 

------------ BorderLayout() ------------


import java.awt.*;

class Bortest
{
 public static void main(String[] args)
 {
  Frame f = new Frame();
  f.setLayout(new BorderLayout());       // Frame에 Layout을 지정

  Button b1 = new Button("OK");
  Button b2 = new Button("CANCEL");
  Button b3 = new Button("b3");
  Button b4 = new Button("b4");
  Button b5 = new Button("b5");
 
  Panel p = new Panel();
  p.setLayout(new BorderLayout());        // panel에 Layout을 지정

  TextField tf = new TextField("",50);
  TextArea ta = new TextArea(10,50);
   
  p.add(tf,BorderLayout.NORTH);
  p.add(b3,BorderLayout.CENTER);
 
  f.add(p,BorderLayout.NORTH);
  f.add(ta,BorderLayout.CENTER);
 
  f.setSize(300,200);
  f.setVisible(true);
 }
}

 

 

 

 

------------ MENU ------------

class Men
{
 public static void main(String[] args)
 {

  Frame f = new Frame();
 
  MenuBar mb = new MenuBar();          // 메뉴바 생성

 

  Menu fm = new Menu("파일");            // 메뉴 생성
  fm.add("파일");                               // 메뉴항목을 메뉴에 추가
  fm.add("열기");
  fm.addSeparator();
  fm.add("닫기");
  fm.add("저장");
  fm.add("새이름으로");
  fm.addSeparator();
  fm.add("출력");
  fm.add("끝");


  Menu em = new Menu("편집");          // 메뉴생성
  em.add("취소");                             // 메뉴항목을 메뉴에 추가
  em.addSeparator();
  em.add("잘라내기");
  em.add("복사하기");
  em.add("붙이기");


  mb.add(fm);                                  // 메뉴바에 메뉴 추가
  mb.add(em);

 

  f.setMenuBar(mb);                         // 프레임에 메뉴바 등록
 
  f.setSize(300,500);
  f.setVisible(true);
 }
}   

 

And