애프릿에서의 그래픽

/* <html> <head><title>그래픽 객체예제 - 선그리기</title></head> <body> <applet code="GraphicsLine" width=350 height=300> </applet> </body> </html> */ import java.awt.*; import java.applet.*; public class GraphicsLine extends Applet { public void paint(Graphics g) { g.drawLine(10, 10, 100, 10); g.drawLine(100, 10, 100, 100); g.drawLine(100, 100, 10, 100); g.drawLine(10, 100, 10, 10); g.drawLine(10, 10, 100, 100); g.drawLine(10, 100, 100, 10); } } /* <html> <head><title>그래픽 객체예제 - 사각형그리기</title></head> <body> <applet code="GraphicsRectangles" width=350 height=300> </applet> </body> </html> */ import java.awt.*; import java.applet.*; public class GraphicsRectangles extends Applet { public void paint(Graphics g) { g.drawRect(10, 10, 100, 100); g.fillRect(120, 10, 100, 100); g.fillRoundRect(10, 120, 100, 100, 15, 15); g.drawRoundRect(120, 120, 100, 100, 30, 40); } } /* <html> <head><title>그래픽 객체예제 - 원 & 호 </title></head> <body> <applet code="GraphicsCircle" width=350 height=300> </applet> </body> </html> */ import java.awt.*; import java.applet.*; public class GraphicsCircle extends Applet { public void paint(Graphics g) { g.drawOval(10, 10, 50, 50); g.fillOval(100, 10, 75, 50); g.drawArc(210, 50, 70, 70, 0, 75); g.fillArc(150, 50, 90, 90, 0, 75); g.drawArc(10, 100, 70, 80, 0, 175); g.fillArc(100, 100, 70, 90, 180, 270); } } /* <html> <head><title>동적그래픽 사각형그리기</title></head> <body> <applet code="DynamicRectangle" width=350 height=300> </applet> </body> </html> */ import java.applet.*; import java.awt.*; public class DynamicRectangle extends Applet { public void paint(Graphics g) { Dimension d = getSize(); int v = d.width/2; int h = d.height/2; int radius = (int)((d.width < d.height) ? 0.4 * d.width : 0.4 * d.height); g.drawRect(v - radius, h - radius, 2 * radius, 2 * radius); } } /* <html> <head><title>Color예제</title></head> <body> <applet code="ColorFont" width=300 height=100> </applet> </body> </html> */ import java.applet.Applet; import java.awt.*; public class ColorFont extends Applet { public void paint(Graphics g) { g.setColor(Color.red); g.drawString("알기쉽게 해설한 JAVA", 50, 50); g.setColor(Color.blue); g.drawString("객체지향 프로그래밍", 50, 80); } } /* <html> <head><title>Color 예제</title></head> <body> <applet code="ColorExam" width=300 height=200> </applet> </body> </html> */ import java.awt.*; import java.applet.*; public class ColorExam extends Applet { // draw lines public void paint(Graphics g) { Color c1 = new Color(255, 100, 100); Color c2 = new Color(100, 255, 100); Color c3 = new Color(100, 100, 255); g.setColor(c1); g.drawLine(0, 0, 100, 100); g.setColor(c2); g.drawLine(40, 25, 250, 180); g.setColor(c3); g.drawLine(20, 150, 400, 40); g.setColor(Color.red); g.drawOval(10, 10, 50, 50); g.fillOval(70, 90, 140, 100); g.setColor(Color.blue); g.drawOval(190, 10, 90, 30); g.drawRect(10, 10, 60, 50); g.setColor(Color.cyan); g.fillRect(100, 10, 60, 50); g.drawRoundRect(190, 10, 60, 50, 15, 15); } } /* <html> <head><title>Font예제</title></head> <body> <applet code="SetFont" width=400 height=150> </applet> </body> </html> */ import java.awt.*; import java.applet.*; public class SetFont extends Applet { Graphics g; Font courier; Font timesroman; Font symbol; Font etc; public void init() { courier = new Font("Courier",Font.BOLD,20); timesroman = new Font("Timesroman",Font.BOLD,20); symbol = new Font("Symbol",Font.BOLD,20); etc = new Font("굴림",Font.BOLD,20); } public void paint(Graphics g) { g.setFont(courier); g.drawString("Teach you self JAVA : Courier ",20,20); g.setFont(timesroman); g.drawString("Complete Reference JAVA : Timesoroman ",20,50); g.setFont(symbol); g.drawString("JAVA Tutorial : Symbol ",20,82); g.setFont(etc); g.drawString("알기쉽게 해설한 자바 : 굴림체",20,118); } } /* <html> <head><title>Font예제</title></head> <body> <applet code="FontExample" width=400 height=200> </applet> </body> </html> */ import java.applet.Applet; import java.awt.*; public class FontExample extends Applet { public void paint(Graphics g) { int baseline = 70; g.setColor(Color.red); g.drawLine(0, baseline, 350, baseline); // 빨간색으로 폰트의 기준선(baseline)을 긋는다 Font font = new Font("SansSerif", Font.PLAIN, 30); g.setFont(font); g.setColor(Color.black); g.drawString("Hi java 안녕하세요?", 5, baseline); // 폰트를 설정한 다음 기준선에 문자열을 출력 FontMetrics font1 = g.getFontMetrics(font); int ascent = font1.getAscent(); // 폰트의 머리선(ascent) 크기를 얻는다 int y = baseline - ascent; g.setColor(Color.green); g.drawLine(0, y, 350, y); // 머리선을 긋는다 int descent = font1.getDescent(); // 폰트의 꼬리선 크기를 얻는다 y = baseline + descent; g.setColor(Color.blue); g.drawLine(0, y, 350, y); // 꼬리선을 긋는다 } }