2007년 08월02일 java

import java.io.*;
class ExceptionTest3 {
 //반드시 try{}catch필수인 경우
 
 public static void main(String ar[]){
  
  //키보드입력=> 표준입력,표준출력
  //System.out=>표준출력
  //System.in=>표준입력
  //명시적으로 예외처리를 요구하는 경우..
  try{
  int su=System.in.read();
  System.out.println("입력한 키보드값:"+su);
 }catch(IOException ex){
   //System.out.println("IO예외발생");
   
  }
  //키보드입력 1글자를 읽는다. 
  
 }//main

}//class


==============카드 레이아웃  CardLayout ===============

Canvas => 그래픽전용 객체
Canvas canRed

import java.awt.*;
import java.awt.event.*;
class CardTest extends Frame
 implements ActionListener{
 //CardLayout,Panel
 CardLayout card=new CardLayout();
 //레이아웃매니저를 멤버변수로 지정
 Panel centerP=new Panel();
 Canvas canRed=new Canvas();
 Canvas canGreen=new Canvas();
 Canvas canBlue=new Canvas();
 ///////////////////////////
 Panel southP=new Panel();
 Button btnRed=new Button("빨강");
 Button btnGreen=new Button("초록");
 Button btnBlue=new Button("파랑");
 Button btnNext=new Button("다음");
 //패널은 일부화면을 나타내는 컨테이너
 //기본레이아웃=>FlowLayout
 CardTest(){
  //Panel을 배치,컴포넌트지정
  centerP.setLayout(card);
  //화면이 바뀌는 부분!
  canRed.setBackground(Color.red);
  centerP.add("red",canRed);
  canGreen.setBackground(Color.green);
  centerP.add("green",canGreen);
  canBlue.setBackground(Color.blue);
  centerP.add("blue",canBlue);
  //////////////////////////////
  southP.add(btnRed);
  southP.add(btnGreen);
  southP.add(btnBlue);
  southP.add(btnNext);
  ////////////////////////////
  this.add("Center",centerP);
  this.add("South",southP);
  //이벤트처리=>WindowEvent처리
  btnRed.addActionListener(this);
 //이벤트소스.addXXXListener(구현클래스);
  btnGreen.addActionListener(this);
  btnBlue.addActionListener(this);
  btnNext.addActionListener(this);
  //////////////////////////////
this.addWindowListener(
 new WindowAdapter(){
  public void windowClosing(WindowEvent e){
   System.exit(0);
  }//재정의
 }//익명내부클래스
); 
  //사이즈,보이기
 setSize(480,272);
 setVisible(true);
 setTitle("카드테스트");
 }//생성
public void actionPerformed(ActionEvent e){
 //실제 버튼을 누르면 호출!
 Object ob=e.getSource();
 if(ob==btnRed){//화면전환=>카드레이아웃
  card.show(centerP,"red");
 }else if(ob==btnGreen){
  card.show(centerP,"green");
 }else if(ob==btnBlue){
  card.show(centerP,"blue");
 }else if(ob==btnNext){
  card.next(centerP);
 }
}//ac
 public static void main(String ar[]){
  new CardTest();
 }//main
}//class

======================================================================================

import java.awt.*;
import java.awt.event.*;
classNullTest extends Frame
 implements MouseMotionListener{
 //레이아웃 null,MouseEvent의 예
 Label lab=new Label("Hello 자바");
 //화면의 원하는 위치에 원하는 크기로 배치
 NullTest(){
 Color col=new Color(200,100,200);
Font fo
=new Font("굴림",Font.ITALIC+Font.BOLD,25);
 lab.setForeground(col);//글자색
 lab.setBackground(Color.blue);
 lab.setFont(fo);//글자체,속성,크기
 lab.setAlignment(Label.CENTER);
 lab.setBounds(100,100,150,30);//위치지정
 this.setLayout(null);
 this.add(lab);
 //이벤트처리
 this.addMouseMotionListener(this);
 /////////////////
 this.addWindowListener(
  new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }//재정의
  }//익명내부클래스
  ); 
 //사이즈,보이기
 setSize(400,400);setVisible(true);  
 }//생성
 
public void mouseDragged(MouseEvent e){
//마우스의 x,y를 알아내서 라벨을 이동

 Random ran=new Random();
 Color col=new Color(ran.nextInt(256),ran.nextInt(256),ran.nextInt(256));
 lab.setBackground(col); //<==>setForeground(col);
 int xp=e.getX();
 int yp=e.getY();
 lab.setLocation(xp,yp);
}
public void mouseMoved(MouseEvent e){


 public static void main(String ar[]){
  new NullTest();
 }//main
}//class

by 케리건 | 2007/08/02 12:55 | Java | 트랙백 | 덧글(1)

트랙백 주소 : http://kerrigan.egloos.com/tb/494196
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 케리건 at 2007/08/02 13:00
음 프레임관련 기초 문법 완성 입니다.

^^ 간바로 케리건

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶