'C'에 해당되는 글 116건

  1. 2007.11.07 AWT>Button by 청웨일
  2. 2007.11.07 AWT>TextField by 청웨일
  3. 2007.11.07 GUI에 AWT컴포넌트 추가하기 by 청웨일
  4. 2007.11.07 Dialog 프로그래밍 by 청웨일
  5. 2007.11.07 ScrollPane by 청웨일

AWT>Button

C/Java : 2007. 11. 7. 11:58

java.awt.Button 클래스


- addActionListener() : 버튼이 클릭되면 통보받는다.

- setLabel() : 버튼을 위한 레이블 텍스트 설정

- removeActionListener() : 버튼과 리스터 클래스 사이의 연결 제거


* 프레임에 버튼 추가하기

import java.awt.*;
import java.awt.event.*;


public class TestButton extends Frame implements ActionListener {
 Button btnExit;                                  //버튼객체의 주소를 할당받을수 있는 변수
 
 public TestButton() {
  btnExit = new Button("Exit");               //실제 객체 생성

//Button의 레이블에 나타날 글꼴 제어
  btnExit.setFont(new Font("Courier", Font.BOLD, 24));
//배경색 설정
  btnExit.setBackground(Color.cyan);

//Cursor객체 : 마우스가 객체 위에 있을때 커서모양 제어
  Cursor curs = new Cursor(HAND_CURSOR);   //손모양 커서로 지정
  btnExit.setCursor(curs);
  btnExit.addActionListener(this);
 
  add(btnExit);
  this.setLayout(new FlowLayout());
 
  addWindowListener(new WinCloser());
  setTitle("Using a Button and an ActionListener");
  setBounds(100,100,300,300);
  setVisible(true);
 }
 //버튼이 클릭될때마다 호출된다.
 public void actionPerformed(ActionEvent ae) {
  if(ae.getActionCommand().equals("Exit"));  

//버튼이 클릭되었을때 어떤 버튼인지 설정한다.
  System.exit(0);
 }
 
 public static void main(String[] args) {
  TestButton td = new TestButton();
 }
}


class WinCloser extends WindowAdapter {
 public void WindowClosing(WindowEvent e) {
  System.exit(0);
 }
}

*


Posted by 청웨일

AWT>TextField

C/Java : 2007. 11. 7. 11:57

- addActionListener() : action이벤트가 발생했을때 통지를 받는다.

- setColumus() : 열의 수 설정

- setText() : 텍스트를 설정/수정한다.

- removeActionListener() : action 리스너 제거

- getListener() : 이 객체롸 연관된 모든 리스너를 배열로 반환


* 프레임에 TextField 객체를 위치시킨다.

import java.awt.*;
import java.awt.event.*;


public class TestTextFields extends Frame {
 TextField tfield1;
 TextField tfield2;
 
 public TestTextFields(){
  tfield1 = new TextField(15);                //보여질 글자수를 미리 설정하여 생성한다.
  tfield2 = new TextField(20);


  tfield1.setEchoChar('*');                    //모든 글자가 '*'로 찍히게 한다.
  tfield2.setText("Some Sample Text");    //기본값을 출력하도록 한다.
  tfield2.setFont(new Font("Couroer", Font.BOLD, 16));   //글꼴 지정
  tfield2.setEditable(false);                  //텍스트 수정 불가
  tfield2.select(12, 15);                        //지정된 텍스트를 블록지정한다.
 
  Panel p1 = new Panel();          //패널생성
  p1.add(tfield1);                      //패널 p1에 TextField1 추가
  p1.add(tfield2);                     //패널 p1에 TextField2 추가
  add(p1);                              //TestTextFields tp에 패널 추가
 
  addWindowListener(new WinCloser());
  setTitle("Using TextFields");
  setBounds(100,100,300,300);
  setVisible(true);
 }
 
 public static void main(String[] args) {
  TestTextFields tp = new TestTextFields();
 }
}


class WinCloser extends WindowAdapter {
 public void windowClosing(WindowEvent e) {
  System.exit(0);
 }
}

*

Posted by 청웨일

컴포넌트

java.awt.Component 클래스 확장


TextField : 한줄 텍스트(길이변화가능, 줄 넘김 불가)

    └ TextArea : 한줄 이상의 덱스트 박스, 스크롤바 지원

Button : 그래픽 컴포넌트

Label

CheckBox : 체크상태를 On/Off할수 있는 스위치박스, 그룹묶기 가능, 여러개 선택가능

    └ CheckBoxGroup : 선택 개수 제한

Choice : 풀다운 메뉴/리스트, 한개의 항목만 선택가능

List : Choice와 유사, 여러개의 항목 출력가능

Menu Component

   ├ MenuBar : 프레임에 첨부 가능, 한번에 한개만 선택가능한 풀다운 리스트

   └ MenuItem : 메뉴에서 항목표현, 선택되었을때 이벤트 발생

Posted by 청웨일

Dialog 프로그래밍

C/Java : 2007. 11. 7. 11:56

- Frame객체나 다른 Dialog는 항상 Dialog객체를 가지고 있다.

- 다이얼로그가 닫힐때까지 다른 처리를 잠그는 modal이거나

  다른 윈도우에서 작업하는 동안 열린 상태로 있게 해주는 modaless일수도 있다.

- Dialog객체는 윈도우 상태가 변할때 윈도우 이벤트가 발생한다.


*

import java.awt.*;
import java.awt.event.*;


public class TestDialog extends Frame implements ActionListener{
 Button btnExit;
 Button btnYes;
 Button btnNo;
 Dialog dlgConfirm;


 //TestDialog생성
 public TestDialog() {
  btnExit = new Button("Exit");             //Exit버튼 생성
  btnExit.addActionListener(this);
  add(btnExit);
 
  this.setLayout(new FlowLayout());      //TestDialog를 위한 레이아웃관리자 설정
 
  dlgConfirm = new Dialog(this);           //다이얼로그를 생성하고 클래스에 부착
  dlgConfirm.setResizable(false);
 
  btnYes = new Button("Yes");             //다이얼로그에 버튼 추가
  btnYes.addActionListener(this);
  btnNo = new Button("No");
  btnNo.addActionListener(this);
  dlgConfirm.add(btnYes);
  dlgConfirm.add(btnNo);


  dlgConfirm.setTitle("Are you sure?");    //다이얼로그의 제목과 크기 설정
  dlgConfirm.setSize(200,100);


//디폴트 BorderLayout()은 서도 다른 버튼을 덮어쓸수 있기 때문에 쓰지 않았다.
  dlgConfirm.setLayout(new FlowLayout());
  addWindowListener(new WinCloser());
  setTitle("Using a Dialog");
  setBounds(100,100,300,300);
  setVisible(true);
 }
 

//actionPerformed는 버튼클릭과 같은 동작 action이벤트가 발생하면 자동으로 호출
 public void actionPerformed(ActionEvent ae) {
  if(ae.getActionCommand().equals("Exit"))
   dlgConfirm.show();                             //Dialog객체를 가져와서 출력한다.
  if(ae.getActionCommand().equals("Yes"))
   System.exit(0);
  if(ae.getActionCommand().equals("No"))
   dlgConfirm.setVisible(false);   //Dialog 사라짐
 }
 
 public static void main(String[] args) {
  TestDialog td = new TestDialog();
 }
}


class WinCloser extends WindowAdapter {
  public void windowClosing(WindowEvent e) {
   System.exit(0);
  }
}

*

Posted by 청웨일

ScrollPane

C/Java : 2007. 11. 7. 11:55

java.awt.ScrollPane클래스


- 오직 한개의 객체만 배치한다.

- 여러 개의 객체를 포함시키려면 패널을 ScrollPane에 붙이고 패널위에 다른 객체를 붙인다.

- 수직 수평 옵션이 존재한다.

- 생성자에게 전달할수 있는 값 :

ScrollPane.SCROLLBARS_AS_NEEDED(기본값)

- 패널의 크기가 ScrollPane의 크기를 초솨할 때만 스크롤 바를 얻는다.

ScrollPane.SCROLLBARS_AS_ALWAYS

ScrollPane.SCROLLBARS_AS_NEVER

*

import java.awt.*;
import java.awt.event.*;

public class TestScrollPane extends Frame{
 ScrollPane sp;
 
 TextField tf1;
 TextField tf2;
 TextField tf3;
 TextField tf4;
 TextField tf5;
 TextField tf6;
 TextField tf7;
 TextField tf8;
 
 public TestScrollPane() {
  tf1 = new TextField("Text Field Number 1");
  tf2 = new TextField("Text Field Number 2");
  tf3 = new TextField("Text Field Number 3");
  tf4 = new TextField("Text Field Number 4");
  tf5 = new TextField("Text Field Number 5");
  tf6 = new TextField("Text Field Number 6");
  tf7 = new TextField("Text Field Number 7");
  tf8 = new TextField("Text Field Number 8");
 
  Panel p1 = new Panel();
  p1.add(tf1);
  p1.add(tf2);
  p1.add(tf3);
  p1.add(tf4);
  p1.add(tf5);
  p1.add(tf6);
  p1.add(tf7);
  p1.add(tf8);
 
  sp = new ScrollPane();       //ScrollPane의 인스턴스화
  sp.add(p1);                        //패널 추가
  add(sp);                           //객체가 아닌 프레임에 ScrollPane 추가
  addWindowListener(new WinCloser());
  setTitle("Using a ScrollPane");
  setBounds(100,100,300,300);
  setVisible(true);
 }
 
 public static void main(String[] args) {
  TestScrollPane tsp = new TestScrollPane();
 }
}

class WinCloser extends WindowAdapter {
 public void windowClosing(WindowEvent e) {
  System.exit(0);
 }
}

*

Posted by 청웨일