import java.applet.*; import java.awt.*; class ExtFrame extends Frame { Applet parent=null; private int last_x, last_y; private Color current_color = Color.black; private Button clear_button; private Choice color_choices; ExtFrame(Applet par,String s,int x, int y, int w, int h) { super(s); parent=par; setLayout(null); setBounds(x,y,w,h); setBackground(Color.white); clear_button = new Button("Clear"); clear_button.setBounds(600,50,60,30); clear_button.setForeground(Color.black); clear_button.setBackground(Color.lightGray); add(clear_button); color_choices = new Choice(); color_choices.setBounds(150,60,80,30); color_choices.addItem("Nikon"); color_choices.addItem("Olympus"); color_choices.addItem("Canon"); color_choices.addItem("Kodak"); color_choices.setForeground(Color.black); color_choices.setBackground(Color.lightGray); add(new Label("Color: ")); add(color_choices); show(); } public boolean handleEvent(Event e) { if (super.handleEvent(e)) { return true; } else { if (e.id == Event.WINDOW_DESTROY) { System.exit(0); } return false; } } public boolean mouseDown(Event e, int x, int y) { last_x = x; last_y = y; return true; } public boolean mouseDrag(Event e, int x, int y) { Graphics g = this.getGraphics(); g.setColor(current_color); g.drawLine(last_x, last_y, x, y); last_x = x; last_y = y; return true; } public boolean action(Event event, Object arg) { if (event.target == clear_button) { Graphics g = getGraphics(); Rectangle r = bounds(); g.setColor(getBackground()); g.fillRect(0, 0, r.width,r.height); return true; } else if (event.target == color_choices) { if (arg.equals("Nikon")) current_color = Color.black; else if (arg.equals("Olympus")) current_color = Color.red; else if (arg.equals("Canon")) current_color = Color.yellow; else if (arg.equals("Kodak")) current_color = Color.green; return true; } else return super.action(event, arg); } public void paint(Graphics g) { my_drawImage(g,30,50,"Tools.jpg"); my_drawImage(g,250, 50,"Fruit.jpg"); my_drawImage(g,250,220,"Fish.jpg"); my_drawImage(g,250,370,"Wine.jpg"); } public void my_drawImage (Graphics g, int x, int y, String name) { Image image = parent.getImage(parent.getDocumentBase(),name); g.drawImage(image,x,y,this); if (x > 100) { g.drawString(name,x+275,y+50); g.drawRect(x,y,image.getWidth(this),image.getHeight(this)); } } } public class DragDrop extends Applet { public void init() { new ExtFrame(this,"Andromeda Graphic Services",0,0,800,600); } }