|
| 1 | +// <applet |
| 2 | +// code = "GraphicsMethods.class" |
| 3 | +// width = "420" |
| 4 | +// height = "420" |
| 5 | +// alt = "Applet Here" |
| 6 | +// name = "GraphicsMethods" |
| 7 | +// align = "center" |
| 8 | +// > |
| 9 | +// </applet> |
| 10 | + |
| 11 | +import java.applet.Applet; |
| 12 | +import java.awt.*; |
| 13 | + |
| 14 | +public class GraphicsMethods extends Applet{ |
| 15 | + public void paint(Graphics g) { |
| 16 | + |
| 17 | +// int getWidth(); |
| 18 | + int w = getWidth(); |
| 19 | +// int getHeight(); |
| 20 | + int h = getHeight(); |
| 21 | +// Dimension getSize(); |
| 22 | + Dimension d = getSize(); |
| 23 | + double wD = d.getWidth(); |
| 24 | + double hD = d.getHeight(); |
| 25 | + |
| 26 | + if(w == wD && h == hD) { |
| 27 | +// void drawString("Message", x, y); |
| 28 | + g.drawString("(" + w + ", " + h + ")", 10, 10); |
| 29 | + } |
| 30 | + |
| 31 | + Font f = new Font("Arial", Font.PLAIN, 28); |
| 32 | +// void setFont(Font f); |
| 33 | + g.setFont(f); |
| 34 | + |
| 35 | +// void setBackground(Color c); |
| 36 | + setBackground(Color.WHITE); |
| 37 | + |
| 38 | + // Color c = new Color(78, 32, 91); |
| 39 | +// void setForeground(Color c); |
| 40 | + setForeground(new Color(78, 32, 91)); // Anonymous Object |
| 41 | + |
| 42 | +// void drawLine(int x1, int y1, int x2, int y2); |
| 43 | + g.drawLine(10, 50, 100, 50); |
| 44 | + |
| 45 | +// void drawRect(int x, int y, int width, int height); |
| 46 | + g.drawRect(10, 100, 100, 70); |
| 47 | + |
| 48 | +// void fillRect(int x, int y, int width, int height); |
| 49 | + g.fillRect(150, 100, 100, 70); |
| 50 | + |
| 51 | +// void draw3DRect(int x, int y, int width, int height, boolean raised); |
| 52 | + g.draw3DRect(10, 200, 100, 70, true); |
| 53 | + |
| 54 | +// void fill3DRect(int x, int y, int width, int height, boolean raised); |
| 55 | + g.fill3DRect(150, 200, 100, 70, true); |
| 56 | + |
| 57 | +// void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); |
| 58 | + g.drawRoundRect(10, 300, 100, 70, 25, 25); |
| 59 | + |
| 60 | +// void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); |
| 61 | + g.fillRoundRect(150, 300, 100, 70, 25, 25); |
| 62 | + |
| 63 | +// void drawOval(int x, int y, int xDia, int yDia); |
| 64 | + g.drawOval(10, 400, 100, 70); |
| 65 | + |
| 66 | +// void fillOval(int x, int y, int xDia, int yDia); |
| 67 | + g.fillOval(150, 400, 100, 70); |
| 68 | + |
| 69 | +// void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle); |
| 70 | + g.drawArc(150, 50, 100, 100, 45, 90); |
| 71 | + |
| 72 | + int x1[] = {10, 30, 60, 90, 100, 150}; |
| 73 | + int y1[] = {500, 520, 500, 530, 500, 520}; |
| 74 | +// void drawPolyLine(int[] x, int[] y, int numSides); |
| 75 | + g.drawPolyline(x1, y1, 5); |
| 76 | + |
| 77 | + int x2[] = {150, 170, 200, 230, 240, 290}; |
| 78 | + int y2[] = {500, 520, 500, 530, 520, 520}; |
| 79 | +// void drawPolygon(int[] x, int[] y, int numSides); |
| 80 | + g.drawPolygon(x2, y2, 5); |
| 81 | + } |
| 82 | +} |
0 commit comments