import java.awt.*; import java.applet.Applet; import line; import circle; import rectangle; import text; public class birla extends Applet { private Choice choiceColor, choiceShape, choiceFill; private Label label1, label2, label3, label4; private TextField textbox; private boolean drawing, fill=false; private String shape = "Rectangle"; private Color color = Color.blue; private int startx, starty, endx, endy; Shape2D obj; public void init() { label1 = new Label("Shape : "); label2 = new Label("Color : "); label3 = new Label("Fill : "); label4 = new Label("Click and drag mouse to draw..."); choiceShape = new Choice(); choiceShape.addItem("Rectangle"); choiceShape.addItem("Circle"); choiceShape.addItem("Line"); choiceShape.addItem("Text"); choiceColor = new Choice(); choiceColor.addItem("Blue"); choiceColor.addItem("Red"); choiceColor.addItem("Green"); choiceFill = new Choice(); choiceFill.addItem("false"); choiceFill.addItem("true"); textbox = new TextField(10); add(label1); add(choiceShape); add(label2); add(choiceColor); add(label3); add(choiceFill); add(textbox); add(label4); setBackground(Color.white); show(); } public boolean mouseDown(Event event, int i, int j) { startx = i; starty = j; drawing = true; obj = null; if (shape.equals("Rectangle")) obj = new rectangle(i, j, color, fill); else if (shape.equals("Circle")) obj = new circle(i, j, color, fill); else if (shape.equals("Line")) obj = new line(i, j, color); else obj = new text(i, j, color, textbox.getText()); return true; } public boolean mouseDrag(Event event, int i, int j) { if (drawing) { endx = i; endy = j; repaint(); } return true; } public boolean mouseUp(Event event, int i, int j) { endx = i; endy = j; repaint(); drawing = false; return true; } public boolean action(Event e, Object o) { if (e.target == choiceShape) { shape = choiceShape.getSelectedItem(); if (shape.equals("Text")) label4.setText("Enter text in the textbox"); else label4.setText("Click and drag mouse to draw..."); } else if (e.target == choiceColor) { String col = choiceColor.getSelectedItem(); if (col.equals("Red")) color = Color.red; else if (col.equals("Blue")) color = Color.blue; else if (col.equals("Green")) color = Color.green; } else if (e.target == choiceFill) { String filled = choiceFill.getSelectedItem(); if (filled.equals("true")) fill = true; else fill = false; } return true; } public void paint(Graphics g) { if (obj != null) { obj.setSecondPoint(endx, endy); obj.draw(g); } } }