Java/AWT
Graphic 도형 그리기
Bohemian life
2012. 4. 13. 22:13
package com.graphic3;//Graphics 도형 그리기 import java.awt.*; import java.awt.event.*; import java.awt.Frame; import java.awt.Color; class GraphicFrame extends Frame{ Color redColor; //Paint 메서드 오버라이딩 //paint 메소드를 재정의하면 프로그램 구동시 자동으로 호출됨 public void paint(Graphics g){ redColor = new Color(255,0,0); g.setColor(redColor); //사각형 x y width height g.drawRect(10,30,40,40); //원(타원) g.fillOval(70,30,40,40); //꼭지점 좌표 int x[] = new int[]{10,30,50,40,20}; int y[] = new int[]{107,90,107,130,130}; //다각형 g.drawPolygon(x,y,x.length); //모서리가 둥근 사각형 // x y width height arWidth arcHeight(마지막 2개는 모깍기 정도) g.drawRoundRect(70,90,40,40,10,10); //선 시작x 시작y 끝x 끝 y g.drawLine(150,50,200,100); g.drawLine(200, 50, 150, 100); } //문자열 x,y public GraphicFrame(){ addWindowListener (new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); System.exit(0); }}); } } public class GraphicTest01 { public static void main(String[] args) { GraphicFrame f = new GraphicFrame(); f.setSize(270,150); f.setVisible(true); } }