Simple brush

xiaoxiao2021-03-06  54

Command.java

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * /

Public interface command {public final static int line = 2; public final static int correng = 8;}

Icrcle.java

Import java.awt. *;

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * / Public class iCircle Implements Shape {Private Color Color; Private INT Y; Private Int Width; Private Int Height

Public iCircle (int X, int y, int width, int hotht, color color) {this.x = x; this.y = y; this.width = width; this.height = height; this.color = color;} Public Void Draw (Graphics G) {G.SetColor (Color); G.drawarc (x, y, width, height, 0, 360);}

}

Iline.java

Import java.awt. *;

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * / Public class iline uste; private int y1; private int x2; private int y2; private color color;

Public = y1; excitation = y2; excitation = y2; this.y2 = y2; this.color = color;

Public Void Draw (Graphics G) {G.SetColor (Color); G. Drawline (x1, y1, x2, y2);}}}}}}}} IRECTANGLE.JAVA

Import java.awt. *; import java.awt.event. *; import java.util.Vector;

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * / Public class reatangle ustements shape {private int x; private int width; private int hoth; private color color;

Public IRECTANGLE (INT X, INT Y, INT Width, INT Height, Color Color) {this.x = x; this.y = y; this.width = width; this.height = height; this.color = color;}

Public Void Draw (Graphics G) {G.SetColor (Color); g.drawRect (x, y, width, height);}

}

Paintapp.java

Import java.awt. *; import java.awt.event. *; import java.util. *;

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * / Public class paintapp extends frame {Panel CommandPanel = new panel (); panel colorpanel = new panel (); Panel shapepanel = new panel ();

Button btnred = new button ("red"); button btngreen = new button ("green"); button btnblue = New Button ("blue");

Button btnline = new button ("line"); Button btnRectangle = New Button ("Rectangle"); button btncircle = new button ("circle");

Button btnundo = new button ("undo"); button btnredo = new button ("redo"); button btnexit = new button ("exit"); Paintboard Paintboard = New Paintboard ();

Public paintapp () {this.setLayout (New borderLayout ());

btnLine.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnLine_actionPerformed (e);}}); btnRectangle.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnRectangle_actionPerformed (e);}} ); Btncircle.addActionListener (new activityListener () {public void actionPerformed (ActionEvent E) {btncircle_actionperformed (e);}});

btnExit.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnExit_actionPerformed (e);}}); btnUndo.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnUndo_actionPerformed (e);}} BTNREDO.ADDACTIONListener (New ActionListener () {public void actionPerformed (ActionEvent E) {btnredo_actionperformed (e);}});

ShapePanel.SetLayout (New flowLayout ()); ShapePanel.Add (btnline, null); ShapePanel.Add (btnRectangle, null); ShapePanel.Add (btncircle, null);

ShapePanel.Add (btnundo, null); ShapePanel.Add (BTNREDO, NULL); ShapePanel.Add (Btnexit, Null);

btnRed.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnRed_actionPerformed (e);}}); btnGreen.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnGreen_actionPerformed (e);}} ); btnBlue.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {btnBlue_actionPerformed (e);}}); colorPanel.setLayout (new FlowLayout ()); colorPanel.add (btnRed, null); colorPanel.add (BTNGREEN, NULL); ColorPanel.Add (btnblue, null);

CommandPanel.setLayout (New BorderLayout ()); CommandPanel.Add (ShapePanel, BorderLayout.North); CommandPanel.Add (ColorPanel, BorderLayout.center);

This.Add (CommandPanel, BorderLayout.South); this.add (Paintboard, BorderLayout.center);

///

Btnline.setForeground; Paintboard.setCommand (Command.Line);

Btnred.SetForeground (color.red); Paintboard.SetColor (Color.Red); ///

}

Void btnexit_Actionperformed (ActionEvent E) {system.exit (0);

Void btnundo_actionperformed (ActionEvent E) {PaintBoard.undo ();

Void btnredo_actionperperformed (ActionEvent E) {Paintboard.Redo ();

void btnLine_actionPerformed (ActionEvent e) {btnLine.setForeground (Color.red); btnRectangle.setForeground (Color.black); btnCircle.setForeground (Color.black); paintBoard.setCommand (Command.LINE);} void btnRectangle_actionPerformed (ActionEvent e) {btnLine.setForeground (Color.black); btnRectangle.setForeground (Color.red); btnCircle.setForeground (Color.black); paintBoard.setCommand (Command.RECTANGLE);} void btnCircle_actionPerformed (ActionEvent e) {btnLine.setForeground (Color .black); btnRectangle.setForeground (Color.black); btnCircle.setForeground (Color.red); paintBoard.setCommand (Command.CIRCLE);} void btnRed_actionPerformed (ActionEvent e) {btnRed.setForeground (Color.red); btnGreen. setForeground (Color.black); btnBlue.setForeground (Color.black); paintBoard.setColor (Color.red);} void btnGreen_actionPerformed (ActionEvent e) {btnRed.setForeground (Color.black); btnGreen.setForeground (Color.red) BtnBlue.setForeground (color.black); Paintboard.SetColor (Color.green); void btnBlue_actionPerformed (ActionEvent e) {btnRed.setForeground (Color.black); btnGreen.setForeground (Color.black); btnBlue.setForeground (Color.red); paintBoard.setColor (Color.blue);}

Public static void main (string [] args) {PaintApp PaintApp = new PaintApp (); PainTapp.setsize (600, 500); PainTapp.setVisible (TRUE);}

}

Paintboard.java

Import java.awt. *; import java.awt.event. *; import java.util. *;

/ ** * @author aassd * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * /

public class PaintBoard extends Canvas implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener {int srcX = 0; int srcY = 0; int lineToX = 0; int lineToY = 0; boolean bMousePressing = false; java.util .Stack vshapes = new java.util.stack (); java.util.stack vdelshapes = new java.util.stack (); private int command = 0; private color color; public void undo () {ix (vshapes.size ()> 0) {Object Shape = vshapes.pop (); VDELSHAPES.PUSH (Shape); repaint ();

} Public void redo () {if (vdelshapes.size ()> 0) {Object Shape = VDELSHAPES.POP (); vshapes.push (shape); repaint ();}} public void setcommand (intechand) {this. Command = Command;} public void setcolor (color color) {this.color = color;}

Public paintboard () {this.addmouselistener (this); this.addmouseMotionListener (this);}

Public void paint (graphics g) {

Dimension size = size (); int width = size.width; int Height = size.height; g.setcolor (color.white); g.FillRect (0, 0, width, height);

Shape shape = null; java.util.enumeration enum = vshapes.elements (); g.setcolor (color.blue); while (enum.hasmoreElements ()) {shape = (shape) enum.nexTelement (); shape.draw (g);

IF (BMousePressing) {G.SetColor (Color); Switch (Command) {Case Command.Line: g.drawline (srcx, srcy, linetox, linetoy); Break; Case Command.Rectangle: IF (LINETOX

Public void mousepressed (mouseevent e) {srcx = E.GETX (); SRCY = E.GETY (); bmousepressing = true;}

Public void mouseeleased (mouseevent e) {linetox = E.GETX (); linetoy = E.GETY (); bmousepressing = false; switch (command) {copy command.line: iline line = new iline (srcx, srcy, linetox, Linetoy, color); vshapes.push (line); break; case command.rectangle: IRECTANGLE Rectangle = NULL; IF (LINETOX

Public void mouseexited (mouseevent e) {}

Public void mousedraged (mouseevent e) {linetox = E.GETX (); linetoy = E.Gety (); repaint ();

Public void mousemoved (mouseevent e) {}

}

Shape.java

Import java.awt. *; import java.awt.event. *;

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

New Post(0)