home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-09-08 | 1.4 KB | 51 lines |
- /* <applet code = "Scribble1" width=200 height=200>
- </applet>
- */
- import java.applet.*;
- import java.awt.*;
- /** Åα«ßΓ«⌐ á»»½ÑΓ, ó ¬«Γ«α«¼ ¿ß»«½∞ºπÑΓß∩ ¼«ñѽ∞ «íαáí«Γ¬¿ ß«íδΓ¿⌐ 1.0 */
- public class Scribble1 extends Applet {
- private int lastx, lasty; // òαá¡∩Γ ¬««αñ¿¡áΓδ ¬παß«αá ¼δΦ¿.
- Button clear_button; // è¡«»¬á Clear.
- Graphics g; // ÄíΩÑ¬Γ Graphics, ¬«Γ«αδ⌐ ¡Ñ«íσ«ñ¿¼« ¡áα¿ß«óáΓ∞.
- /** ê¡¿µ¿á½¿ºáµ¿∩ ¬¡«»¬¿ ¿ «íΩѬΓá Graphics */
- public void init() {
- clear_button = new Button("Clear");
- this.add(clear_button);
- g = this.getGraphics();
- }
- /** ÉÑᬵ¿∩ ¡á ¡áªáΓ¿Ñ ¬¡«»¬¿ ¼δΦ¿ */
- public boolean mouseDown(Event e, int x, int y) {
- lastx = x; lasty = y;
- return true;
- }
- /** ÉÑᬵ¿∩ ¡á »ÑαÑΓá߬¿óá¡¿Ñ ß »«¼«Θ∞ε ¼δΦ¿ */
- public boolean mouseDrag(Event e, int x, int y) {
- g.setColor(Color.black) ;
- g.drawLine(lastx, lasty, x, y);
- lastx = x; lasty = y;
- return true;
- }
- /** ÉÑᬵ¿∩ ¡á ¡áªáΓ¿Ñ ¬½áó¿Φ¿ [æ] */
- public boolean keyDown(Event e, int key) {
- if ((e.id == Event.KEY_PRESS) && (key == 'ß' ) ) {
- clear() ;
- return true;
- }
- else return false;
- }
- /** ÉÑᬵ¿∩ ¡á ¡áªáΓ¿Ñ ¬¡«»¬¿ Clear */
- public boolean action(Event e, Object arg) {
- if (e.target == clear_button) {
- clear();
- return true;
- }
- else return false;
- }
- /** îÑΓ«ñ ñ½∩ ßΓ¿αá¡¿∩ ¬áαá¬π½Ñ⌐ */
- public void clear() {
- g.setColor(this.getBackground());
- g.fillRect(0, 0, bounds().width, bounds().height);
- }
- }
-