[Original] Use a rubber strip technical drawing

xiaoxiao2021-03-06  78

[Original] Use a rubber strip technical drawing

In the software development of the drawing graphics, it faces the rubber strip technology. The so-called rubber strip technology is a record of mouse movement during the drawing process, and the complete graph is drawn when the mouse is loose. The application of a simple rubber strip technology is given below, which is drawn on the applet and can only draw a rectangle, which is very helpful for the image crop:

.. / ** * @ (#) xortest.java * * Copyright 2004 Opensource Develop Team All rights reserved * / import java.applet.Applet; import java.awt *;. Import java.awt.event.MouseAdapter; import java .awt.event.mouseevent; import java.awt.event.mousemotionAdapter;

/ ** * Draw a rectangle on the applet, when the second drawing is to be drawn, the rectangle drawn last time disappears. * @Author @ @see java.applet.applet * @since jdk 1.3 * @version 1.0 07/05/2004 * / public class xortest extends applet {point pressed, last; // Record the starting point and mouse to move End point coordinate Boolean firstRect; // only draw a rectangle

Public void init () {addmouselistener (new mouseadapter () {public void mousepressed (mouseEvent e) {firstRect = true; // Make sure a rectangular PRESSED = E.GETPOINT (); // Get start point coordinate}

Public void mousereleased (mouseevent e) {if (PRESSED! = null) {Point release = E.GETPOINT (); Rectangle Clip = new rectangle (); // Clip To the final determined rectangular graphics g = getGraphics (); Dimension Size = getSize ();

Try {clip.x = PRESSED.X; clip.y = PRESSED.Y; clip.width = math.abs (released.x - press.x); clip.height = math.abs (released.y - pressed.y );

G.clearRect (0, 0, size.width, size.height); g.drawRect (clip.x, clip.y, clip.width, clip.height); // Draw final rectangle} Finally {g.dispose ();}}} Public void mouseclicked (mouseevent e) {repaint ();}};

AddMouseMotionListener () {public void mousedragged (mouseevent e) {point location (); // mouse current location Graphics g = getGraphics ();

转载请注明原文地址:https://www.9cbs.com/read-121077.html

New Post(0)