/** * @(#)scribble.java * * scribble Applet application * * @By Paul (source mostly from a java book) * @version 1.00 11/26/2008 * edited on 12/11/2008 * made with: JCreator * instructions: click and drag the mouse to draw in this * awesome Java Applet. Click the "clear" button to clear. */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class scribble extends Applet { int last_x, last_y; public void init() { this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { last_x = e.getX(); last_y = e.getY(); } }); this.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Graphics g = getGraphics(); int x = e.getX(), y = e.getY(); g.setColor(Color.black); g.drawLine(last_x, last_y, x, y); last_x = x; last_y = y; } }); Button b = new Button("Clear"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Graphics g = getGraphics(); g.setColor(getBackground()); g.fillRect(0, 0, getSize().width, getSize().height); } }); this.add(b); } public void paint(Graphics g) { g.drawString("Click and drag to draw.", 50, 60 ); } }