블로그 이미지
하루, 글. 그림. 영상매체. 표현을 도와주는 기기들. 도전 중. 동화다아아
    동화다아아

    카테고리

    분류 전체보기 (176)
    잡담 (1)
    IT 기기-리뷰&뉴스 (7)
    리뷰 - 도서 (1)
    리뷰 - 영상 (0)
    리뷰 - 그림/음악 (1)
    내장형 하드웨어 (163)
    Total
    Today
    Yesterday

    - Point, Rectangle, Dimension 클래스
     → 애플릿에서 main()은 웹 브라우저 or 애플릿 뷰어이다.
     → 즉, 웹브라우져 안에는 모바일 자바 가상머신이 포함되어 있다.

    - Color 클래스
     → 화면의 색은 Color 클래스의 객체에 의해서 생성된다.
     → 색상은 기본 Red, Green, Blue의 혼합으로 결정
     → 세가지 기본 색상의 농도는 0~255사이의 정수값이나, 0~1.0까지의 실수값으로 나타낼 수 있으며 , 적색, 녹색, 청색의 순으로 표시
     → 세가지 색은 각각 256가지의 농도이며 조합하여 1600만색을 만들 수 있다.
     → 예제

    // 노란색 바탕의 애플릿에 푸른색과 검정색으로 글씨를 쓰는 프로그램
    import
     java.applet.Applet;
    import java.awt.*;

    public class ShowColor extends Applet
    {
      public void paint (Graphics g)
      {
        setBackground (Color.yellow);
        g.setColor (Color.blue); 
        g.drawString ("String is blue"3040);
        g.setColor (Color.black);
        g.drawString ("String is black"3060);
        g.setColor (Color.pink);
        g.drawString ("String is pink"3080);
        // 아래를 보려면 애플릿 뷰어로 봐야 한다.
        showStatus ("Drawing Color: " + g.getColor()); 
        setSize(250,140);    
      }
    }

     → 실행 결과



    - Font 클래스
     → Font 클래스는 글꼴이나 크기 정보 등을 가지고 있다.
     → Font 클래스의 생성자 Font(String FontName, int style, int size)
     → 인수는 각각 폰트의 이름, 모양, 크기를 넣는다.
     → 예제

    // 여러가지 폰트와 스타일의 글체를 출력하는 프로그램
    import
     java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Font;

    public class ShowFont extends Applet
    {
      public void paint(Graphics g)
      {
        Font serif = new Font("Serif"Font.PLAIN, 12);
        Font monospaced = new Font("Monospaced"Font.ITALIC, 24);
        Font sansSerif = new Font("SansSerif"Font.BOLD, 10);

        g.setFont(serif);
        g.drawString("Seref plain 12 point"3030);

        g.setFont(monospaced);
        g.drawString("Monospaced italic 24 point"3060);

        g.setFont(sansSerif);
        g.drawString("SansSeref bold 10 point"3080);
        showStatus("current font : " + g.getFont().toString());
      }
    }

     → 실행 결과



    - FontMatrics 클래스
     → Font의 크기에 대한 상세한 정보가 정의되어 있다.
     → FontMatrics 객체는 Component 클래스에 정의된 getFontMatrics() 메소드로 구한다.
     → 예제

    // FontMetrics 객체를 이용하여 폰트에 관한 정보를 검색하는 프로그램
    import
     java.applet.Applet;
    import java.awt.*;

    public class ShowFontMetrics extends Applet
    {
      public void paint(Graphics g)
      {
        Font serif = new Font("Serif"Font.PLAIN, 15);
        
        g.setFont(serif);
        g.drawString("Serif plain 12 point"3030);
        int ascent, descent, height, leading;
        ascent = g.getFontMetrics().getAscent();
        descent = g.getFontMetrics().getDescent();
        height = g.getFontMetrics().getHeight();
        leading = g.getFontMetrics().getLeading();

        g.drawString("Ascent : " + ascent, 3045);
        g.drawString("Descent : " + descent, 3060);
        g.drawString("Height : " + height, 3075);
        g.drawString("Leading : " + leading, 3090);    
        setSize(250140);
      }
    }

     → 실행 결과

    - 직선, 원, 사각형, XOR, 부채꼴 모드 그리기
     → 예제

    // 직선을 그리는 프로그램
    import
     java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Color;

    public class LineDrawing extends Applet
    {
      public void paint(Graphics g)
      {
        // 직선
        g.drawLine(201527060);
        // 원
        g.fillOval(40705035);
        g.drawOval(120702060);
        g.fillOval(170705237);
        // 사각형
        g.drawRect(801503030);
        g.fillRect(1501506030);
        // XOR 모드
        g.setColor (Color.green);
        g.fillRect (202208050);
        g.setColor (Color.blue);
        g.fillOval (1202209050);
        setBackground (Color.white);
        g.setXORMode (Color.white);
        g.setColor (Color.orange);
        g.fillRect (2302209050);
        g.fillRect (2802309030);
        // 부채꼴
        g.drawArc(40320606040300);
        g.fillArc(140320606040300);
        g.drawArc(2403206060100120);
        g.fillArc(3003206060100120);
        setSize(450400);
      }
    }

     → 실행 결과

     

    Posted by 동화다아아
    , |

    최근에 달린 댓글

    최근에 받은 트랙백

    글 보관함