⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scribble.java

📁 java 绘图的代码,应用applet, awt, 可嵌入网页进行手写和绘图等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 {    return (mousex != e.getX() || mousey != e.getY()); } /*   Method is a key segment in the operations where   there are more than 2 variables deviating to   makeup a graphical operation.   This method calculates the new values for the   global varibles drawX and drawY according to   the new positions of the mouse cursor.   This method eleviates the possibility that   a negative width or height can occur. */ public void setActualBoundry() {       /*         If the any of the current mouse coordinates         are smaller than the origin coordinates, meaning         if drag occured in a negative manner, where either         the x-shift occured from right and/or y-shift occured         from bottom to top.       */       if (mousex < Orx || mousey < Ory)       {          /*            if the current mouse x coordinate is smaller            than the origin x coordinate,            equate the drawX to be the difference between            the current width and the origin x coordinate.          */          if (mousex < Orx)          {             OrWidth = Orx - mousex;             drawX   = Orx - OrWidth;          }          else          {             drawX    = Orx;             OrWidth  = mousex - Orx;          }          /*            if the current mouse y coordinate is smaller            than the origin y coordinate,            equate the drawY to be the difference between            the current height and the origin y coordinate.          */          if (mousey < Ory)          {             OrHeight = Ory - mousey;             drawY    = Ory - OrHeight;          }          else          {             drawY    = Ory;             OrHeight = mousey - Ory;          }       }       /*         Else if drag was done in a positive manner meaning         x-shift occured from left to right and or y-shift occured         from top to bottom       */       else       {          drawX    = Orx;          drawY    = Ory;          OrWidth  = mousex - Orx;          OrHeight = mousey - Ory;       } } /*   Method sets all the drawing varibles to the default   state which is the current position of the mouse cursor   Also the height and width varibles are zeroed off. */ public void setGraphicalDefaults(MouseEvent e) {    mousex   = e.getX();    mousey   = e.getY();    prevx    = e.getX();    prevy    = e.getY();    Orx      = e.getX();    Ory      = e.getY();    drawX    = e.getX();    drawY    = e.getY();    OrWidth  = 0;    OrHeight = 0; } /*   Method will be activated when mouse is being dragged.   depending on what operation is the opstatus, the switch   statement will call the relevent operation */ public void mouseDragged(MouseEvent e) {    updateMouseCoordinates(e);    switch (opStatus)    {       /* If opStatus is PEN_OP  then call penOperation method */       case PEN_OP   : penOperation(e);                       break;       /* If opStatus is LINE_OP then call lineOperation method */       case LINE_OP  : lineOperation(e);                       break;       /* If opStatus is RECt_OP  then call rectOperation method */       case RECT_OP  : rectOperation(e);                       break;       /* If opStatus is OVAL_OP then call ovalOperation method */       case OVAL_OP  : ovalOperation(e);                       break;       /* If opStatus is FRECT_OP  then call frectOperation method */       case FRECT_OP : frectOperation(e);                       break;       /* If opStatus is FOVAL_OP then call fovalOperation method */       case FOVAL_OP : fovalOperation(e);                       break;       /* If opStatus is ERASER_OP then call eraserOperation method */       case ERASER_OP: eraserOperation(e);                       break;    } } /*    Method will be activated when mouse has been release from pressed \    mode. At this stage the method will call the finalization routines    for the current operation. */ public void mouseReleased(MouseEvent e) {    /* Update current mouse coordinates to screen */    updateMouseCoordinates(e);    switch (opStatus)    {       /* If opStatus is PEN_OP  then call releasedPen method */       case PEN_OP    : releasedPen();                        break;       /* If opStatus is LINE_OP then call releasedLine method */       case LINE_OP   : releasedLine();                        break;       /* If opStatus is RECT_OP  then call releasedRect method */       case RECT_OP   : releasedRect();                        break;       /* If opStatus is OVAL_OP then call releasedOval method */       case OVAL_OP   : releasedOval();                        break;       /* If opStatus is FRECT_OP  then call releasedFrect method */       case FRECT_OP  : releasedFRect();                        break;       /* If opStatus is FOVAL_OP then call releasedFoval method */       case FOVAL_OP  : releasedFOval();                        break;       /* If opStatus is ERASER_OP then call releasedEraser method */       case ERASER_OP : releasedEraser();                        break;    } } /*    Method will be activated when mouse enters the applet area.    This method will then update the current mouse x and coordinates    on the screen. */ public void mouseEntered(MouseEvent e) {    updateMouseCoordinates(e); } /*   Method will set the main system color according to the   current color status. */ public void setMainColor() {    switch (colorStatus)    {       case 1 : mainColor = Color.black;                break;       case 2:  mainColor = Color.blue;                break;       case 3:  mainColor = Color.green;                break;       case 4:  mainColor = Color.red;                break;       case 5:  mainColor = Color.magenta;                break;       case 6:  mainColor = Color.orange;                break;       case 7:  mainColor = Color.pink;                break;       case 8:  mainColor = Color.gray;                break;       case 9:  mainColor = Color.yellow;                break;       case 10: mainColor = userDefinedColor;                break;    } } /*   Method is invoked when mouse has been released   and current operation is Pen */ public void releasedPen() {    initialPen = true; } /*   Method is invoked when mouse has been released   and current operation is Line */ public void releasedLine() {    if ((Math.abs(Orx-mousex)+Math.abs(Ory-mousey)) != 0)    {       System.out.println("Line has been released....");       initialLine = true;       Graphics g  = drawPanel.getGraphics();       g.setColor(mainColor);       g.drawLine(Orx,Ory,mousex,mousey);    } } /*   Method is invoked when mouse has been released   and current operation is Eraser */ public void releasedEraser() {    initialEraser = true;    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor.white);    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2); } /*   Method is invoked when mouse has been released   and current operation is Rectangle */ public void releasedRect() {    initialRect = true;    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    g.drawRect(drawX,drawY,OrWidth,OrHeight); } /*   Method is invoked when mouse has been released   and current operation is Oval */ public void releasedOval() {    initialOval = true;    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    g.drawOval(drawX,drawY,OrWidth,OrHeight); } /*   Method is invoked when mouse has been released   and current operation is Fill-Rectangle */ public void releasedFRect() {    initialFRect = true;    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    g.fillRect(drawX,drawY,OrWidth,OrHeight); } /*   Method is invoked when mouse has been released   and current operation is Fill-Oval */ public void releasedFOval() {    initialFOval = true;    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    g.fillOval(drawX,drawY,OrWidth,OrHeight); } /*   Method displays the mouse coordinates x and y values   and updates the mouse status bar with the new values. */ public void updateMouseCoordinates(MouseEvent e) {    String xCoor ="";    String yCoor ="";    if (e.getX() < 0) xCoor = "0";    else    {       xCoor = String.valueOf(e.getX());    }    if (e.getY() < 0) xCoor = "0";    else    {       yCoor = String.valueOf(e.getY());    }    mouseStatusBar.setText("x:"+xCoor+"   y:"+yCoor); } /*   Method updates user-defined values for udefRGB */ public void updateRGBValues() {    udefRedValue = redSlider.getValue();    udefGreenValue = greenSlider.getValue();    udefBlueValue = blueSlider.getValue();    if (udefRedValue > 255)       udefRedValue = 255;    if (udefRedValue < 0 )       udefRedValue =0;    if (udefGreenValue > 255)       udefGreenValue = 255;    if (udefGreenValue < 0 )       udefGreenValue =0;    if (udefBlueValue > 255)       udefBlueValue = 255;    if (udefBlueValue < 0 )       udefBlueValue =0;    redValue.setText(String.valueOf(udefRedValue));    greenValue.setText(String.valueOf(udefGreenValue));    blueValue.setText(String.valueOf(udefBlueValue));    userDefinedColor = new Color(udefRedValue,udefGreenValue,udefBlueValue);    userDefButton.setBackground(userDefinedColor);    Graphics g = udefdemcolPanel.getGraphics();    g.setColor(userDefinedColor);    g.fillRect(0,0,800,800); } /*   Method updates mouse coordinates if mouse has been clicked */ public void mouseClicked(MouseEvent e) {    updateMouseCoordinates(e);    switch (opStatus)    {       case 9  : splineOperation(e);                 break;       case 10 : polygonOperation(e);                 break;    }} /*   Method updates mouse coordinates if mouse has exited applet */ public void mouseExited(MouseEvent e) {    updateMouseCoordinates(e); } /*   Method updates mouse coordinates if mouse has moved */ public void mouseMoved(MouseEvent e) {    updateMouseCoordinates(e); } /*   Method updates mouse coordinates if mouse has been pressed */ public void mousePressed(MouseEvent e) {    updateMouseCoordinates(e); }} // End of Scribble

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -