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

📄 scribble.java

📁 java 绘图的代码,应用applet, awt, 可嵌入网页进行手写和绘图等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                break;       case  2:  colorStatusBar.setText("Blue");                 break;       case  3:  colorStatusBar.setText("Green");                 break;       case  4:  colorStatusBar.setText("Red");                 break;       case  5:  colorStatusBar.setText("Purple");                 break;       case  6:  colorStatusBar.setText("Orange");                 break;       case  7:  colorStatusBar.setText("Pink");                 break;       case  8:  colorStatusBar.setText("Gray");                 break;       case  9: colorStatusBar.setText("Yellow");                break;       case 10: colorStatusBar.setText("User Defined Color");                break;    }    /*      Set main color, to equivelent colorStatus value    */    setMainColor();    updateRGBValues(); } public void adjustmentValueChanged(AdjustmentEvent e) {    updateRGBValues(); } /*   Method will clear the whole drawPanel with   the current background color */ public void clearPanel(Panel p) {    opStatusBar.setText("Clear");    Graphics g = p.getGraphics();    g.setColor(p.getBackground());    g.fillRect(0,0,p.getBounds().width,p.getBounds().height);  } /*   Method will emulate a pen style graphic.   by drawing a line from the previous mouse corrdinates   to the current mouse coordinates.   Note: In initial attempt the previous mouse coordinates         are set to the current mouse coordinates so as         not to begin the pen graphic from an unwanted         arbitrary point. */ public void penOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialPen)    {       setGraphicalDefaults(e);       initialPen = false;       g.drawLine(prevx,prevy,mousex,mousey);    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*          set mouse coordinates to          current mouse position       */       mousex = e.getX();       mousey = e.getY();       /*          draw a line from the previous mouse coordinates          to the current mouse coordinates       */       g.drawLine(prevx,prevy,mousex,mousey);       /*          set the current mouse coordinates to          previous mouse coordinates for next time       */       prevx = mousex;       prevy = mousey;    } } /*   Method will emulate a line drawing graphic.   By drawing a shadow line for an origin mouse   coordinate pair to a moving mouse coordinate   pair, until the mouse has been release from   dragmode. */ public void lineOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialLine)    {       setGraphicalDefaults(e);       g.setXORMode(xorColor);       g.drawLine(Orx,Ory,mousex,mousey);       initialLine=false;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*         Delete previous line shadow         by xor-ing the graphical object       */       g.setXORMode(xorColor);       g.drawLine(Orx,Ory,mousex,mousey);       /* Update new mouse coordinates */       mousex = e.getX();       mousey = e.getY();       /* Draw line shadow */       g.drawLine(Orx,Ory,mousex,mousey);    } } /*   Method will emulate a rectangle drawing graphic.   By drawing a shadow rectangle for an origin mouse   coordinate pair to a moving mouse coordinate   pair, until the mouse has been release from   dragmode. */ public void rectOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialRect)    {       setGraphicalDefaults(e);       initialRect = false;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*         Delete previous rectangle shadow         by xor-ing the graphical object       */       g.setXORMode(drawPanel.getBackground());       g.drawRect(drawX,drawY,OrWidth,OrHeight);       /* Update new mouse coordinates */       mousex = e.getX();       mousey = e.getY();       /* Check new mouse coordinates for negative errors */       setActualBoundry();       /* Draw rectangle shadow */       g.drawRect(drawX,drawY,OrWidth,OrHeight);    } } /*   Method will emulate a oval drawing graphic.   By drawing a shadow oval for an origin mouse   coordinate pair to a moving mouse coordinate   pair, until the mouse has been release from   dragmode. */ public void ovalOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialOval)    {       setGraphicalDefaults(e);       initialOval=false;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*         Delete previous oval shadow         by xor-ing the graphical object       */       g.setXORMode(xorColor);       g.drawOval(drawX,drawY,OrWidth,OrHeight);       /* Update new mouse coordinates */       mousex = e.getX();       mousey = e.getY();       /* Check new mouse coordinates for negative errors */       setActualBoundry();       /* Draw oval shadow */       g.drawOval(drawX,drawY,OrWidth,OrHeight);    } } /*   Method will emulate a filled-rectangle drawing graphic.   By drawing a shadow filled-rectangle for an origin mouse   coordinate pair to a moving mouse coordinate   pair, until the mouse has been release from   dragmode. */ public void frectOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialFRect)    {       setGraphicalDefaults(e);       initialFRect=false;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*         Delete previous rectangle shadow         by xor-ing the graphical object       */       g.setXORMode(xorColor);       g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);       /* Update new mouse coordinates */       mousex = e.getX();       mousey = e.getY();       /* Check new mouse coordinates for negative errors */       setActualBoundry();       /* Draw rectangle shadow */       g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);    } } /*   Method will emulate a filled-oval drawing graphic.   By drawing a shadow filled-oval for an origin mouse   coordinate pair to a moving mouse coordinate   pair, until the mouse has been release from   dragmode. */ public void fovalOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    g.setColor(mainColor);    /*      In initial state setup default values      for mouse coordinates    */    if (initialFOval)    {       setGraphicalDefaults(e);       initialFOval = false;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       /*         Delete previous oval shadow         by xor-ing the graphical object       */       g.setXORMode(xorColor);       g.drawOval(drawX,drawY,OrWidth,OrHeight);       /* Update new mouse coordinates */       mousex = e.getX();       mousey = e.getY();       /* Check new mouse coordinates for negative errors */       setActualBoundry();       /* Draw oval shadow */       g.drawOval(drawX,drawY,OrWidth,OrHeight);    } } /*   Method will emulate a eraser graphic.   By drawing a filled rectangle of background color,   with the current mouse coordinates being the center   of the rectangle. This is done until the mouse has   been release from dragmode */ public void eraserOperation(MouseEvent e) {    Graphics g  = drawPanel.getGraphics();    /*      In initial state setup default values      for mouse coordinates    */    if (initialEraser)    {       setGraphicalDefaults(e);       initialEraser = false;       g.setColor(mainColor.white);       g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);       g.setColor(Color.black);       g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);       prevx = mousex;       prevy = mousey;    }    /*      Make sure that the mouse has actually      moved from its previous position.    */    if (mouseHasMoved(e))    {       g.setColor(mainColor.white);       g.drawRect(prevx-eraserLength, prevy-eraserLength,eraserLength*2,eraserLength*2);       /* Get current mouse coordinates */       mousex  = e.getX();       mousey  = e.getY();       /* Draw eraser block to panel */       g.setColor(mainColor.white);       g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);       g.setColor(Color.black);       g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);       prevx = mousex;       prevy = mousey;    } } /*    Method will draw a polygon of N points on drawable surface */ public void polygonOperation(MouseEvent e) {    if (initialPolygon)    {       prevx = e.getX();       prevy = e.getY();       initialPolygon = false;    }    else    {       mousex = e.getX();       mousey = e.getY();       Graphics g = drawPanel.getGraphics();       g.setColor(mainColor);       g.drawLine(prevx,prevy,mousex,mousey);       prevx = mousex;       prevy = mousey;    } }/*   Not fully implemented spline operation*/public void splineOperation(MouseEvent e){   if(initialSpline)   {      initialSpline = false;   }} /*   Method determines weather the mouse has moved   from its last recorded position.   If mouse has deviated from previous position,   the value returned will be true, otherwise   the value that is returned will be false. */ public boolean mouseHasMoved(MouseEvent e)

⌨️ 快捷键说明

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