`

Applet画图程序

阅读更多

双击右键才显示功能菜单。。。

 

 import java.applet.Applet;
 import java.awt.BasicStroke;
 import java.awt.Button;
 import java.awt.Canvas;
 import java.awt.Choice;
 import java.awt.Color;
 import java.awt.Container;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.FileDialog;
 import java.awt.FlowLayout;
 import java.awt.Frame;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.Label;
 import java.awt.MediaTracker;
 import java.awt.MenuItem;
 import java.awt.Panel;
 import java.awt.PopupMenu;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionAdapter;
 import java.awt.event.MouseMotionListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.Ellipse2D.Double;
 import java.awt.geom.Line2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.PrintStream;
 import java.io.Serializable;
 import java.util.Vector;
 import javax.imageio.ImageIO;
 import javax.swing.JColorChooser;
 import javax.swing.JPanel;
 
 public class DrawImage extends Applet
   implements ItemListener, MouseListener, MouseMotionListener, ActionListener
 {
   private static final long serialVersionUID = 1L;
   int count = 6;
   Vector v = new Vector();
   Image[] img = new Image[this.count];
 
   int myWidth = 0; int myHeight = 0;
   int widthcount = 0;
 
   boolean[] b = new boolean[this.count];
   int[] width = new int[this.count]; int[] height = new int[this.count]; int[] w = new int[this.count];
   int[] h = new int[this.count]; int[] wid = new int[this.count]; int[] hei = new int[this.count];
   int[] ww = new int[this.count]; int[] hh = new int[this.count];
 
   int startX = 0; int startY = 0; int endX = 0; int endY = 0;
   Canvas startObj = null; Canvas endObj = null;
   String drawclear = "";
   int clickX = 0; int clickY = 0; int moveX = 0; int moveY = 0;
 
   DrawImage.canvas[] can = null;
   DrawImage.myCanvas[] mycan = new DrawImage.myCanvas[this.count];
   Canvas curcan = null;
   Canvas curdelcan = null;
   Image curimg = null;
 
   JPanel jp = new JPanel(null);
   MediaTracker mt = new MediaTracker(this);
 
   PopupMenu popMenu2 = new PopupMenu();
   MenuItem menuItem1 = null;
   MenuItem menuItem2 = null;
   MenuItem menuItem3 = null;
   MenuItem menuItem4 = null;
   MenuItem menuItem5 = null;
 
   int x = -1; int y = -1;
   int con = 1;
   int Econ = 5;
 
   int toolFlag = 0;
 
   Color c = new Color(0, 0, 0);
 
   BasicStroke size = new BasicStroke(this.con, 0, 
     2);
   DrawImage.Point cutflag = new DrawImage.Point(-1, -1, this.c, 6, this.con);
 
   Vector paintInfo = null;
   int n = 1;
 
   FileInputStream picIn = null;
   FileOutputStream picOut = null;
 
   ObjectInputStream VIn = null;
   ObjectOutputStream VOut = null;
   Panel toolPanel;
   Button eraser;
   Button drLine;
   Button drCircle;
   Button drRect;
   Button clear;
   Button pen;
   Choice ColChoice;
   Choice SizeChoice;
   Choice EraserChoice;
   Button colchooser;
   Label 颜色;
   Label 大小B;
   Label 大小E;
   Button openPic;
   Button savePic;
   FileDialog openPicture;
   BufferedImage bi = null;
   Graphics2D g2d = null;
 
   public void init()
   {
     int width2 = Toolkit.getDefaultToolkit().getScreenSize().width;
     int height2 = Toolkit.getDefaultToolkit().getScreenSize().height;
 
     this.bi = new BufferedImage(width2, height2, 1);
 
     this.img[0] = getImage(getCodeBase(), "image/1.gif");
     this.img[1] = getImage(getCodeBase(), "image/2.gif");
     this.img[2] = getImage(getCodeBase(), "image/3.gif");
     this.img[3] = getImage(getCodeBase(), "4.gif");
     this.img[4] = getImage(getCodeBase(), "5.gif");
     this.img[5] = getImage(getCodeBase(), "6.gif");
 
     resize(800, 600);
     setLayout(null);
 
     for (int i = 0; i < this.img.length; ++i) {
       this.mt.addImage(this.img[i], 0);
     }
     try
     {
       this.mt.waitForAll();
     }
     catch (Exception ex)
     {
       System.err.println(ex.toString());
     }
 
     add(this.jp);
     this.jp.setBounds(0, 0, 800, 80);
 
     for (int i = 0; i < this.img.length; ++i)
     {
       this.mycan[i] = new DrawImage.myCanvas(this.img[i]);
       this.width[i] = this.img[i].getWidth(this);
       this.height[i] = this.img[i].getHeight(this);
       this.jp.add(this.mycan[i]);
       this.mycan[i].setBounds(100 + 5 * (i + 1) + this.widthcount, 5, 
         this.img[i].getWidth(this), this.img[i].getHeight(this));
      this.widthcount += this.img[i].getWidth(this);
     }
 
     this.menuItem1 = new MenuItem("隐藏图像工具栏");
     this.menuItem2 = new MenuItem("显示图像工具栏");
     this.menuItem3 = new MenuItem("清空画面");
 
     this.menuItem4 = new MenuItem("显示绘图工具栏");
     this.menuItem5 = new MenuItem("隐藏绘图工具栏");
 
     this.popMenu2.add(this.menuItem1);
     this.popMenu2.add(this.menuItem2);
     this.popMenu2.add(this.menuItem3);
     this.popMenu2.addSeparator();
     this.popMenu2.add(this.menuItem4);
     this.popMenu2.add(this.menuItem5);
 
     add(this.popMenu2);
 
     this.menuItem1.addActionListener(this);
     this.menuItem2.addActionListener(this);
     this.menuItem3.addActionListener(this);
     this.menuItem4.addActionListener(this);
     this.menuItem5.addActionListener(this);
 
     this.toolPanel = new Panel(null);
     this.toolPanel.setLayout(new FlowLayout());
 
     this.paintInfo = new Vector();
 
     this.ColChoice = new Choice();
     this.ColChoice.add("black");
     this.ColChoice.add("red");
     this.ColChoice.add("blue");
     this.ColChoice.add("green");
     this.ColChoice.addItemListener(this);
 
     this.SizeChoice = new Choice();
     this.SizeChoice.add("1");
     this.SizeChoice.add("3");
     this.SizeChoice.add("5");
     this.SizeChoice.add("7");
     this.SizeChoice.add("9");
     this.SizeChoice.addItemListener(this);
 
     this.EraserChoice = new Choice();
     this.EraserChoice.add("5");
     this.EraserChoice.add("9");
     this.EraserChoice.add("13");
     this.EraserChoice.add("17");
     this.EraserChoice.addItemListener(this);
 
     this.clear = new Button("清除");
     this.eraser = new Button("橡皮");
     this.pen = new Button("画笔");
     this.drLine = new Button("画直线");
     this.drCircle = new Button("画圆形");
     this.drRect = new Button("画矩形");
 
     this.openPic = new Button("打开图画");
     this.savePic = new Button("保存图画");
 
    this.colchooser = new Button("显示调色板");
 
     this.clear.addActionListener(this);
     this.eraser.addActionListener(this);
     this.pen.addActionListener(this);
     this.drLine.addActionListener(this);
     this.drCircle.addActionListener(this);
     this.drRect.addActionListener(this);
     this.openPic.addActionListener(this);
     this.savePic.addActionListener(this);
     this.colchooser.addActionListener(this);
 
     this.颜色 = new Label("画笔颜色", 1);
     this.大小B = new Label("画笔大小", 1);
     this.大小E = new Label("橡皮大小", 1);
 
     this.toolPanel.add(this.openPic);
     this.toolPanel.add(this.savePic);
 
     this.toolPanel.add(this.pen);
     this.toolPanel.add(this.drLine);
     this.toolPanel.add(this.drCircle);
     this.toolPanel.add(this.drRect);
 
     this.toolPanel.add(this.颜色);
     this.toolPanel.add(this.ColChoice);
     this.toolPanel.add(this.大小B);
     this.toolPanel.add(this.SizeChoice);
     this.toolPanel.add(this.colchooser);
 
     this.toolPanel.add(this.eraser);
     this.toolPanel.add(this.大小E);
     this.toolPanel.add(this.EraserChoice);
 
     this.toolPanel.add(this.clear);
 
     add(this.toolPanel);
     this.toolPanel.setBounds(0, 0, 900, 80);
     this.toolPanel.setBackground(Color.black);
     this.toolPanel.setVisible(false);
 
     addMouseListener(this);
     addMouseMotionListener(this);
   }
 
   public void itemStateChanged(ItemEvent e)
   {
     if (e.getSource() == this.ColChoice)
     {
       String name = this.ColChoice.getSelectedItem();
 
       if (name == "black")
       {
         this.c = new Color(0, 0, 0);
       }
       else if (name == "red")
       {
         this.c = new Color(255, 0, 0);
       }
       else if (name == "green")
       {
         this.c = new Color(0, 255, 0);
       } else {
         if (name != "blue")
           return;
         this.c = new Color(0, 0, 255);
       }
     }
     else if (e.getSource() == this.SizeChoice)
     {
       String selected = this.SizeChoice.getSelectedItem();
 
       if (selected == "1")
       {
         this.con = 1;
       }
       else if (selected == "3")
       {
         this.con = 3;
       }
       else if (selected == "5")
       {
         this.con = 5;
       }
       else if (selected == "7")
       {
         this.con = 7;
       }
       else if (selected == "9")
       {
         this.con = 9;
       }
       this.size = 
         new BasicStroke(this.con, 0, 
         2);
     } else {
       if (e.getSource() != this.EraserChoice)
         return;
       String Esize = this.EraserChoice.getSelectedItem();
 
       if (Esize == "5")
       {
         this.Econ = 10;
       }
       else if (Esize == "9")
       {
         this.Econ = 18;
       }
       else if (Esize == "13")
       {
         this.Econ = 26;
       } else {
         if (Esize != "17")
           return;
         this.Econ = 51;
       }
     }
   }
 
   public void actionPerformed(ActionEvent e)
   {
     if (e.getSource() == this.menuItem1)
     {
       this.jp.setVisible(false);
       this.toolPanel.setVisible(true);
       repaint();
     }
     else if (e.getSource() == this.menuItem2)
     {
       this.jp.setVisible(true);
       this.toolPanel.setVisible(false);
       repaint();
     }
     else if (e.getSource() != this.menuItem3)
     {
       if (e.getSource() == this.menuItem4)
       {
         this.toolPanel.setVisible(true);
         repaint();
       }
       else if (e.getSource() == this.menuItem5)
       {
         this.toolPanel.setVisible(false);
         repaint();
       }
     }
 
     if (e.getSource() == this.pen)
     {
       this.toolFlag = 0;
     }
 
     if (e.getSource() == this.eraser)
     {
      this.toolFlag = 1;
     }
 
     if (e.getSource() == this.clear)
     {
       this.toolFlag = 2;
       this.paintInfo.removeAllElements();
       repaint();
     }
 
     if (e.getSource() == this.drLine)
     {
       this.toolFlag = 3;
     }
 
     if (e.getSource() == this.drCircle)
     {
       this.toolFlag = 4;
     }
 
     if (e.getSource() == this.drRect)
     {
       this.toolFlag = 5;
     }
 
     if (e.getSource() == this.colchooser)
     {
       Color newColor = JColorChooser.showDialog(this, "调色板", this.c);
       this.c = newColor;
     }
 
     if (e.getSource() == this.openPic)
     {
    	 Frame f = new DrawImage.fileDialog("File Dialog Demo!");
       f.setVisible(false);
       f.setSize(100, 100);
       FileDialog fd1 = new FileDialog(f, "File Dialog", 0);
       fd1.setVisible(true);
       try
       {
         this.curimg = ImageIO.read(new File(fd1.getDirectory(), fd1.getFile()));
 
         Canvas ca = new DrawImage.canvas(this.curimg);
         add(ca);
         ca.setBounds(100, 200, this.curimg.getWidth(this), 
           this.curimg.getHeight(this));
         validate();
         this.curcan = null;
       }
       catch (IOException e1)
       {
         e1.printStackTrace();
       }
 
     }
 
     if (e.getSource() != this.savePic)
       return;
     Frame f = new DrawImage.fileDialog("File Dialog Demo!");
     f.setVisible(false);
     f.setSize(100, 100);
 
     FileDialog fd = new FileDialog(f, "File Dialog", 1);
     fd.setVisible(true);
     try
     {
       if (fd.getFile() == null)
         return;
       String pathStr = fd.getDirectory();
 
       pathStr = pathStr.replace("\\", "\\\\");
       String path = pathStr + fd.getFile();
 
       ImageIO.write(this.bi, "jpg", new File(path));
     }
     catch (IOException e2)
     {
       e2.printStackTrace();
     }
   }
 
   public void mouseClicked(MouseEvent e)
   {
     clickhere(e);
   }
 
   public void mouseEntered(MouseEvent e)
   {
   }
 
   public void mouseExited(MouseEvent e)
   {
   }
 
   public void update(Graphics g)
   {
     paint(g);
   }
 
   public void mousePressed(MouseEvent e)
   {
     DrawImage.Point p2;
     switch (this.toolFlag)
     {
     case 3:
       this.x = e.getX();
       this.y = e.getY();
       p2 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p2);
       break;
     case 4:
       this.x = e.getX();
       this.y = e.getY();
       p2 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p2);
       break;
     case 5:
       this.x = e.getX();
       this.y = e.getY();
       p2 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p2);
     }
   }
 
   public void mouseReleased(MouseEvent e)
   {
     if ((e.getButton() == 3) && (e.getClickCount() == 2))
     {
       this.popMenu2.show(e.getComponent(), e.getX(), e.getY());
     }
     DrawImage.Point p3;
     switch (this.toolFlag)
     {
     case 0:
       this.paintInfo.addElement(this.cutflag);
       break;
     case 1:
       this.paintInfo.addElement(this.cutflag);
       break;
     case 3:
       this.x = e.getX();
       this.y = e.getY();
       p3 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p3);
       this.paintInfo.addElement(this.cutflag);
       repaint();
       break;
     case 4:
       this.x = e.getX();
       this.y = e.getY();
       p3 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p3);
       this.paintInfo.addElement(this.cutflag);
       repaint();
       break;
     case 5:
       this.x = e.getX();
       this.y = e.getY();
       p3 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p3);
       this.paintInfo.addElement(this.cutflag);
       repaint();
     case 2:
     }
   }
 
   public void mouseDragged(MouseEvent e)
   {
     DrawImage.Point p1;
     switch (this.toolFlag)
     {
     case 0:
       this.x = e.getX();
       this.y = e.getY();
       p1 = new DrawImage.Point(this.x, this.y, this.c, this.toolFlag, this.con);
       this.paintInfo.addElement(p1);
       repaint();
       break;
     case 1:
       this.x = e.getX();
       this.y = e.getY();
       p1 = new DrawImage.Point(this.x, this.y, null, this.toolFlag, this.Econ);
       this.paintInfo.addElement(p1);
       repaint();
     }
   }
 
   public void mouseMoved(MouseEvent e)
   {
     if (!(this.toolPanel.isVisible()))
       return;
     setCursor(new Cursor(1));
   }
 
   public void clickhere(MouseEvent e)
   {
     if (this.curcan == null)
       return;
     if (e.getModifiers() != 4)
       return;
     Canvas ca = new DrawImage.canvas(this.curimg);
     add(ca);
     ca.setBounds(e.getX(), e.getY(), this.curimg.getWidth(this), 
       this.curimg.getHeight(this));
     validate();
     this.curcan = null;
   }
 
   public void paint(Graphics g)
   {
     this.g2d = ((Graphics2D)g);
     this.g2d = ((Graphics2D)this.bi.getGraphics());
 
    this.n = this.paintInfo.size();
 
     if (this.toolFlag == 2)
     {
       g.clearRect(0, 0, getSize().width, getSize().height);
       this.g2d.clearRect(0, 0, getSize().width, getSize().height);
     }
 
     for (int i = 0; i < this.n - 1; ++i)
     {
       DrawImage.Point p1 = (DrawImage.Point)this.paintInfo.elementAt(i);
       DrawImage.Point p2 = (DrawImage.Point)this.paintInfo.elementAt(i + 1);
       this.size = 
         new BasicStroke(p1.boarder, 0, 
         2);
 
       this.g2d.setColor(p1.col);
       this.g2d.setStroke(this.size);
 
       if (p1.tool != p2.tool)
         continue;
       switch (p1.tool)
       {
       case 0:
         Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
         this.g2d.draw(line1);
         break;
       case 1:
         g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
         this.g2d.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
         break;
       case 3:
         Line2D line2 = null;
 
         int X = Math.abs(p2.x - p1.x);
         int Y = Math.abs(p2.y - p1.y);
 
         if (X >= Y)
         {
           line2 = new Line2D.Double(p1.x, p1.y, p2.x, p1.y);
         }
         else
         {
           line2 = new Line2D.Double(p1.x, p1.y, p1.x, p2.y);
         }
 
         this.g2d.draw(line2);
         break;
       case 4:
         Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, 
           Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
         this.g2d.draw(ellipse);
         break;
       case 5:
         Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, 
           Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
         this.g2d.draw(rect);
         break;
       case 6:
         ++i;
       case 2:
       }
 
     }
 
     g.drawImage(this.bi, 0, 0, this);
   }
 
   public double radians(int degrees)
   {
     return (degrees * 3.141592653589793D / 180.0D);
   }
 
   class MyWindowAdapter extends WindowAdapter
   {
     DrawImage.fileDialog sf;
 
     public MyWindowAdapter(DrawImage.fileDialog paramfileDialog)
     {
       this.sf = paramfileDialog;
     }
 
     public void windowClosing(WindowEvent we)
     {
       this.sf.setVisible(false);
     }
   }
 
   class Point
     implements Serializable
   {
     int x;
     int y;
     Color col;
     int tool;
     int boarder;
 
     Point(int paramInt1, int paramInt2, Color paramColor, int paramInt3, int paramInt4)
     {
       this.x = paramInt1;
       this.y = paramInt2;
       this.col = paramColor;
       this.tool = paramInt3;
       this.boarder = paramInt4;
     }
   }
 
   class canvas extends Canvas
   {
     private static final long serialVersionUID = 1L;
     Image im = null;
     int X;
     int Y;
     int bufferX;
     int bufferY;
     int bufferWidth;
     int bufferHeight;
 
     public canvas(Image paramImage)
     {
       setCursor(new Cursor(13));
       this.im = paramImage;
 
       addMouseListener(new MouseAdapter()
       {
         public void mousePressed(MouseEvent e)
         {
           DrawImage.canvas.this.clickcanvas(e);
         }
 
         public void mouseReleased(MouseEvent e)
         {
           Canvas mcan = (Canvas)e.getSource();
 
           int mtop = mcan.getY(); int mleft = mcan.getX(); int mwidth = 
             mcan.getWidth(); int mheight = mcan.getHeight();
 
           DrawImage.canvas.this.X = (mleft + e.getX() - DrawImage.this.clickX);
           DrawImage.canvas.this.Y = (mtop + e.getY() - DrawImage.this.clickY);
 
           DrawImage.canvas.this.bufferX = DrawImage.canvas.this.X;
           DrawImage.canvas.this.bufferY = DrawImage.canvas.this.Y;
           DrawImage.canvas.this.bufferWidth = mwidth;
           DrawImage.canvas.this.bufferHeight = mheight;
 
           DrawImage.canvas.this.drawBufferImage();
         }
       });
       addKeyListener(new KeyAdapter()
       {
         public void keyPressed(KeyEvent e)
         {
           if (e.getKeyCode() == 127)
             DrawImage.canvas.this.removecanvas(e);
         }
       });
       addMouseMotionListener(new MouseMotionAdapter()
       {
         public void mouseDragged(MouseEvent e)
         {
           DrawImage.canvas.this.movecanvas(e);
         }
       });
     }
 
     public void movecanvas(MouseEvent e)
     {
       Canvas mcan = (Canvas)e.getSource();
 
       int mtop = mcan.getY(); int mleft = mcan.getX(); int mwidth = 
         mcan.getWidth(); int mheight = mcan.getHeight();
 
       clearImage();
 
       mcan.setBounds(mleft + e.getX() - DrawImage.this.clickX, mtop + e.getY() - DrawImage.this.clickY, 
         mwidth, mheight);
 
       for (int i = 0; i < DrawImage.this.v.size(); ++i)
       {
         Vector v1 = (Vector)DrawImage.this.v.elementAt(i);
         if (((Canvas[])v1.elementAt(0))[0].equals(mcan))
         {
           ((int[])v1.elementAt(1))[0] = mcan.getX();
           ((int[])v1.elementAt(1))[1] = mcan.getY();
           ((int[])v1.elementAt(1))[2] = mcan.getWidth();
           ((int[])v1.elementAt(1))[3] = mcan.getHeight();
         } else {
           if (!(((Canvas[])v1.elementAt(0))[1].equals(mcan)))
             continue;
           ((int[])v1.elementAt(1))[4] = mcan.getX();
           ((int[])v1.elementAt(1))[5] = mcan.getY();
           ((int[])v1.elementAt(1))[6] = mcan.getWidth();
           ((int[])v1.elementAt(1))[7] = mcan.getHeight();
         }
       }
 
       ((DrawImage)getParent()).repaint();
     }
 
     public void removecanvas(KeyEvent e)
     {
       try
       {
         Canvas mcan = (Canvas)e.getSource();
         ((DrawImage)getParent()).remove(DrawImage.this.curdelcan);
         for (int i = DrawImage.this.v.size() - 1; i >= 0; --i)
         {
           Vector v1 = (Vector)DrawImage.this.v.elementAt(i);
           if ((!(((Canvas[])v1.elementAt(0))[0].equals(mcan))) && 
             (!(((Canvas[])v1.elementAt(0))[1].equals(mcan)))) continue;
           DrawImage.this.v.removeElementAt(i);
         }
         ((DrawImage)getParent()).validate();
         ((DrawImage)getParent()).repaint();
       }
       catch (NullPointerException ex)
       {
         return;
       }
     }
 
     public void clickcanvas(MouseEvent e)
     {
       DrawImage.this.curdelcan = ((Canvas)e.getSource());
       DrawImage.this.clickX = e.getX();
       DrawImage.this.clickY = e.getY();
       ((DrawImage)getParent()).repaint();
 
       if (((DrawImage)getParent()).drawclear.equals(""))
         return;
       if ((((DrawImage)getParent()).startObj == null) && 
         (((DrawImage)getParent()).endObj == null)) {
         ((DrawImage)getParent()).startObj = ((Canvas)e.getSource()); } else {
         if ((((DrawImage)getParent()).startObj == null) || 
           (((DrawImage)getParent()).endObj != null) || 
           (((DrawImage)getParent()).startObj == (Canvas)
           e.getSource()))
           return;
         ((DrawImage)getParent()).endObj = ((Canvas)e.getSource());
         Vector v1 = new Vector();
         v1.addElement(new Canvas[] { DrawImage.this.startObj, DrawImage.this.endObj });
         v1.addElement(new int[] { DrawImage.this.startObj.getX(), DrawImage.this.startObj.getY(), 
           DrawImage.this.startObj.getWidth(), DrawImage.this.startObj.getHeight(), DrawImage.this.endObj.getX(), 
           DrawImage.this.endObj.getY(), DrawImage.this.endObj.getWidth(), 
           DrawImage.this.endObj.getHeight() });
         DrawImage.this.v.addElement(v1);
         ((DrawImage)getParent()).drawclear = "";
 
         ((DrawImage)getParent()).startObj = null;
         ((DrawImage)getParent()).endObj = null;
       }
     }
 
     public void paint(Graphics g)
     {
       g.drawImage(this.im, 0, 0, this);
     }
 
     public void drawBufferImage()
     {
       Graphics2D g2 = (Graphics2D)DrawImage.this.bi.getGraphics();
 
       g2.drawImage(this.im, this.X, this.Y, this);
       g2.dispose();
     }
 
     public void clearImage()
     {
       Graphics2D g2 = (Graphics2D)DrawImage.this.bi.getGraphics();
 
       g2.clearRect(this.bufferX, this.bufferY, this.bufferWidth, this.bufferHeight);
     }
   }
 
   class fileDialog extends Frame
   {
     private static final long serialVersionUID = 1L;
 
     fileDialog(String title)
     {
       super(title);
       DrawImage.MyWindowAdapter adapter = new DrawImage.MyWindowAdapter(this);
       addWindowListener(adapter);
     }
   }
 
   class myCanvas extends Canvas
   {
     private static final long serialVersionUID = 1L;
     Image im = null;
     String str = "";
 
     public myCanvas(String paramString)
     {
       this.str = paramString;
     }
 
     public myCanvas(Image paramImage)
     {
       setCursor(new Cursor(12));
       this.im = paramImage;
       addMouseListener(new MouseAdapter()
       {
         public void mousePressed(MouseEvent e)
         {
           DrawImage.myCanvas.this.clickmyCanvas(e);
         }
       });
     }
 
     public void clickmyCanvas(MouseEvent e)
     {
       ((DrawImage)getParent().getParent()).drawclear = "";
       ((DrawImage)getParent().getParent()).startObj = null;
       ((DrawImage)getParent().getParent()).endObj = null;
 
       DrawImage.this.curcan = ((Canvas)e.getSource());
       DrawImage.this.curimg = this.im;
     }
 
     public void paint(Graphics g)
     {
       if (this.str.equals(""))
       {
         g.drawImage(this.im, 0, 0, this);
       }
       else
       {
         g.drawString(this.str, 20, getHeight() / 2);
       }
     }
   }
 }

 

分享到:
评论

相关推荐

    ibus-table-chinese-erbi-1.4.6-3.el7.x64-86.rpm.tar.gz

    1、文件内容:ibus-table-chinese-erbi-1.4.6-3.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/ibus-table-chinese-erbi-1.4.6-3.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊

    基于微信小程序的新乡学院自习室预约系统.zip

    选择Java后台技术和MySQL数据库,在前台界面为提升用户体验,使用Jquery、Ajax、CSS等技术进行布局。 系统包括两类用户:学生、管理员。 学生用户只要实现了前台信息的查看,打开首页,查看网站介绍、自习室信息、在线留言、轮播图信息公告等,通过点击首页的菜单跳转到对应的功能页面菜单,包括网站首页、自习室信息、注册登录、个人中心、后台登录。 学生用户通过账户账号登录,登录后具有所有的操作权限,如果没有登录,不能在线预约。学生用户退出系统将注销个人的登录信息。 管理员通过后台的登录页面,选择管理员权限后进行登录,管理员的权限包括轮播公告管理、老师学生信息管理和信息审核管理,管理员管理后点击退出,注销登录信息。 管理员用户具有在线交流的管理,自习室信息管理、自习室预约管理。 在线交流是对前台用户留言内容进行管理,删除留言信息,查看留言信息。

    面向基层就业个性化大学生服务平台(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计

    面向基层就业个性化大学生服务平台(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 【功能需求】 面向基层就业个性化大学生服务平台(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 面向基层就业个性化大学生服务平台中的管理员角色主要负责了如下功能操作。 (1)职业分类管理功能需求:对职业进行划分分类管理等。 (2)用户管理功能需求:对用户信息进行维护管理等。 (3)职业信息管理功能需求:对职业信息进行发布等。 (4)问卷信息管理功能需求:可以发布学生的问卷调查操作。 (5)个性化测试管理功能需求:可以发布个性化测试试题。 (6)试题管理功能需求:对测试试题进行增删改查操作。 (7)社区交流管理功能需求:对用户的交流论坛信息进行维护管理。 面向基层就业个性化大学生服务平台中的用户角色主要负责了如下功能操作。 (1)注册登录功能需求:没有账号的用户,可以输入账号,密码,昵称,邮箱等信息进行注册操作,注册后可以输入账号和密码进行登录。 (2)职业信息功能需求:用户可以对职业信息进行查看。 (3)问卷信息功能需求:可以在线进行问卷调查答卷操作。 (4)社区交流功能需求:可以在线进行社区交流。 (5)个性化测试功能需求:可以在线进行个性化测试。 (6)公告资讯功能需求:可以查看浏览系统发布的公告资讯信息。 【环境需要】 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.数据库:MySql 5.7/8.0等版本均可; 【购买须知】 本源码项目经过严格的调试,项目已确保无误,可直接用于课程实训或毕业设计提交。里面都有配套的运行环境软件,讲解视频,部署视频教程,一应俱全,可以自己按照教程导入运行。附有论文参考,使学习者能够快速掌握系统设计和实现的核心技术。

    三菱Fx3u程序:自动检测包装机电机控制模板,PLC脉冲与伺服定位,手自动切换功能,三菱Fx3u程序:自动检测包装机电机控制模板-涵盖伺服定位与手自动切换功能,三菱Fx3u程序,自动检测包装机 该

    三菱Fx3u程序:自动检测包装机电机控制模板,PLC脉冲与伺服定位,手自动切换功能,三菱Fx3u程序:自动检测包装机电机控制模板——涵盖伺服定位与手自动切换功能,三菱Fx3u程序,自动检测包装机。 该程序六个电机,plc本体脉冲控制3个轴,3个1pg控制。 程序内包括伺服定位,手自动切,功能快的使用,可作为模板程序,很适合新手。 ,三菱Fx3u程序; 自动检测包装机; 六个电机; PLC脉冲控制; 伺服定位; 手自动切换; 功能快捷键; 模板程序。,三菱Fx3u PLC控制下的自动包装机程序:六电机伺服定位与手自动切换模板程序

    基于多尺度集成极限学习机回归 附Matlab代码.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

    计及信息间隙决策与多能转换的综合能源系统优化调度模型:实现碳经济最大化与源荷不确定性考量,基于信息间隙决策与多能转换的综合能源系统优化调度模型:源荷不确定性下的高效碳经济调度策略,计及信息间隙决策及多

    计及信息间隙决策与多能转换的综合能源系统优化调度模型:实现碳经济最大化与源荷不确定性考量,基于信息间隙决策与多能转换的综合能源系统优化调度模型:源荷不确定性下的高效碳经济调度策略,计及信息间隙决策及多能转的综合能源系统优化调度 本代码构建了含风电、光伏、光热发电系统、燃气轮机、燃气锅炉、电锅炉、储气、储电、储碳、碳捕集装置的综合能源系统优化调度模型,并考虑P2G装置与碳捕集装置联合运行,从而实现碳经济的最大化,最重要的是本文引入了信息间隙决策理论考虑了源荷的不确定性(本代码的重点)与店铺的47代码形成鲜明的对比,注意擦亮眼睛,认准原创,该代码非常适合修改创新,,提供相关的模型资料 ,计及信息间隙决策; 综合能源系统; 优化调度; 多能转换; 碳经济最大化; 风电; 光伏; 燃气轮机; 储气; 储电; 储碳; 碳捕集装置; P2G装置联合运行; 模型资料,综合能源系统优化调度模型:基于信息间隙决策和多能转换的原创方案

    IPG QCW激光模块电源驱动电路设计与实现:包含安全回路、紧急放电回路及光纤互锁功能的多版本原理图解析,IPG QCW激光模块电源驱动电路设计与实现:含安全回路、紧急放电及光纤互锁等多重保护功能的原

    IPG QCW激光模块电源驱动电路设计与实现:包含安全回路、紧急放电回路及光纤互锁功能的多版本原理图解析,IPG QCW激光模块电源驱动电路设计与实现:含安全回路、紧急放电及光纤互锁等多重保护功能的原理图解析,IPG QCW激光模块电源驱动电路, 包含安全回路,紧急放电回路,光纤互锁回路等, 元件参数请根据实际设计适当调整,此电路仅供参考,不提供pcb文件 原理图提供PDF和KICAD两个版本。 ,IPG激光模块; QCW激光电源驱动; 安全回路; 紧急放电回路; 光纤互锁回路; 原理图PDF和KICAD版本。,IPG激光模块电源驱动电路图解:含安全与紧急放电回路

    基于LSSVM的短期电力负荷预测模型及其性能评估:结果揭露精确度与误差分析,LSSVM在短期电力负荷预测中的结果分析:基于均方根误差、平均绝对误差及平均相对百分误差的评估 ,LSSVM最小二乘支持向量

    基于LSSVM的短期电力负荷预测模型及其性能评估:结果揭露精确度与误差分析,LSSVM在短期电力负荷预测中的结果分析:基于均方根误差、平均绝对误差及平均相对百分误差的评估。,LSSVM最小二乘支持向量机做短期电力负荷预测。 结果分析 均方根误差(RMSE):0.79172 平均绝对误差(MAE):0.4871 平均相对百分误差(MAPE):13.079% ,LSSVM(最小二乘支持向量机);短期电力负荷预测;均方根误差(RMSE);平均绝对误差(MAE);平均相对百分误差(MAPE),LSSVM在电力负荷短期预测中的应用及性能分析

    libmtp-examples-1.1.14-1.el7.x64-86.rpm.tar.gz

    1、文件内容:libmtp-examples-1.1.14-1.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/libmtp-examples-1.1.14-1.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊

    《基于 Transformer 的光学字符识别模型》(毕业设计,源码,教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计.zip

    资源内项目源码是均来自个人的课程设计、毕业设计或者具体项目,代码都测试ok,都是运行成功后才上传资源,答辩评审绝对信服的,拿来就能用。放心下载使用!源码、说明、论文、数据集一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 4、如有侵权请私信博主,感谢支持

    2023-04-06-项目笔记 - 第四百一十六阶段 - 4.4.2.414全局变量的作用域-414 -2025.02.21

    2023-04-06-项目笔记-第四百一十六阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.414局变量的作用域_414- 2025-02-21

    MINIST数据集和春风机器学习框架

    MINIST数据集和春风机器学习框架

    ibus-table-chinese-wu-1.4.6-3.el7.x64-86.rpm.tar.gz

    1、文件内容:ibus-table-chinese-wu-1.4.6-3.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/ibus-table-chinese-wu-1.4.6-3.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊

    宿舍管理系统(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计

    宿舍管理系统(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 【功能需求】 系统拥有管理员和学生两个角色,主要具备系统首页、个人中心、学生管理、宿舍信息管理、宿舍分配管理、水电费管理、进入宿舍管理、出入宿舍管理、维修信息管理、卫生信息管理、考勤信息管理、留言板、交流论坛、系统管理等功能模块。 【环境需要】 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.数据库:MySql 5.7/8.0等版本均可; 【购买须知】 本源码项目经过严格的调试,项目已确保无误,可直接用于课程实训或毕业设计提交。里面都有配套的运行环境软件,讲解视频,部署视频教程,一应俱全,可以自己按照教程导入运行。附有论文参考,使学习者能够快速掌握系统设计和实现的核心技术。

    基于智能算法的无人机路径规划研究 附Matlab代码.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

    人凤飞飞凤飞飞是粉色丰富

    人凤飞飞凤飞飞是粉色丰富

    2024蓝桥杯嵌入式学习资料

    2024蓝桥杯嵌入式学习资料

    image_download_1740129191509.jpg

    image_download_1740129191509.jpg

    基于Multisim仿真的带优先病房呼叫系统设计(仿真图)

    基于Multisim仿真的带优先病房呼叫系统设计(仿真图) 设计一个病房呼叫系统。 功能 (1)当有病人紧急呼叫时,产生声,光提示,并显示病人的编号; (2)根据病人的病情设计优先级别,当有多人呼叫时,病情严重者优先; (3)医护人员处理完当前最高级别的呼叫后,系统按优先级别显示其他呼叫病人的病号。

    基于STM32F103的3.6kW全桥逆变器资料:并网充电放电、智能切换与全方位保护方案,基于STM32F103的3.6kW全桥逆变器资料:并网充电放电、智能控制与全方位保护方案,逆变器光伏逆变器,3

    基于STM32F103的3.6kW全桥逆变器资料:并网充电放电、智能切换与全方位保护方案,基于STM32F103的3.6kW全桥逆变器资料:并网充电放电、智能控制与全方位保护方案,逆变器光伏逆变器,3.6kw储能逆变器全套资料 STM32储能逆变器 BOOST 全桥 基于STM32F103设计,具有并网充电、放电;并网离网自动切;485通讯,在线升级;风扇智能控制,提供过流、过压、短路、过温等全方位保护。 基于arm的方案区别于dsp。 有PCB、原理图及代码ad文件。 ,逆变器; 储能逆变器; STM32F103; 3.6kw; 485通讯; 全方位保护; 智能控制; 方案区别; PCB文件; 原理图文件; ad文件。,基于STM32F103的3.6kw储能逆变器:全方位保护与智能控制

Global site tag (gtag.js) - Google Analytics