资源简介

java大作业--画图板。可以绘图(包含铅笔工具及多种形状)、调色、调节笔头粗细和形状、橡皮、吸管、保存图片、打开图片、剪切、复制、粘贴、撤销。

资源截图

代码片段和文件信息

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import palettetool.PaletteStep;
import palettetool.PaletteTool;

public class DrawingBoardPanel extends JPanel implements MouseListener
MouseMotionListener {
private static final long serialVersionUID = 1L;
private int stepCounts = 0;
private int maxStepCounts = 20;
private PaletteTool thisPaletteTool;
private PaletteStep thisPaletteStep;
private List paletteSteps;
private BufferedImage tempImage;
private BufferedImage backupImage;
private InfoPanel infoPanel;
private OperateHistoryPanel opPanel;
private static Robot robot = null;
private File file = null;
private int w = 480;
private int h = 360;
static {
try {
robot = new Robot();
} catch (AWTException e1) {
e1.printStackTrace();
}
}

public DrawingBoardPanel() {
super();
paletteSteps = new ArrayList(maxStepCounts);
this.setPreferredSize(new Dimension(w h));
this.addMouseListener(this);
this.addMouseMotionListener(this);
backupImage = new BufferedImage(w h BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D) backupImage.getGraphics();
g2.setColor(Color.WHITE);
g2.fillRect(0 0 w h);
}

public DrawingBoardPanel(File file) {
super();
if (file != null && file.exists()) {
this.file = file;
try {
backupImage = ImageIO.read(file);
w = backupImage.getWidth();
h = backupImage.getHeight();
} catch (IOException e) {
e.printStackTrace();
backupImage = null;
}
}
this.setPreferredSize(new Dimension(w h));
paletteSteps = new ArrayList(maxStepCounts);
this.addMouseListener(this);
this.addMouseMotionListener(this);
}

public void save() {
save(file);
}

public void save(File file) {
BufferedImage savedImage = new BufferedImage(w h
BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) savedImage.getGraphics();
if (stepCounts == 0)
g.drawImage(backupImage 0 0 null);
else
g.drawImage(tempImage 0 0 null);
for (int i = 0; i < stepCounts; i++) {
paletteSteps.get(i).draw(g);
}
try {
ImageIO.write(savedImage “jpg“ file);
} catch (IOException e) {
e.printStackTrace();
}
}

public void back(int steps) {
if (0 <= steps && steps < maxStepCounts) {
stepCounts = steps;
repaint();
}
}

public void setThisPaletteTool(PaletteTool tool) {
this.thisPaletteTool = tool;
}

public void setInfoPanel

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件          0  2015-05-14 13:32  大作业--画图板\.metadata\.lock

     文件     250993  2015-05-19 16:17  大作业--画图板\.metadata\.log

     文件         20  2015-05-14 13:33  大作业--画图板\.metadata\.mylyn\.taskListIndex\segments.gen

     文件         32  2015-05-14 13:33  大作业--画图板\.metadata\.mylyn\.taskListIndex\segments_1

     文件        250  2015-05-17 23:54  大作业--画图板\.metadata\.mylyn\.tasks.xml.zip

     文件        438  2015-05-14 13:34  大作业--画图板\.metadata\.mylyn\repositories.xml.zip

     文件        250  2015-05-18 00:15  大作业--画图板\.metadata\.mylyn\tasks.xml.zip

     文件       4855  2015-05-16 04:07  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\0\504353033efb00141b85b9eb67c4dc3b

     文件        360  2015-05-17 04:32  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\0\f012f2235efc0014187cc9cae2dbe46a

     文件        976  2015-05-15 20:37  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\1\a06d2c30fffa00141ba4e3dbae5da969

     文件         78  2015-05-17 00:07  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\1\a0ab5dace5fb0014103cc8b0f4f19749

     文件       1694  2015-05-17 02:21  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\1\b0275e7a58fc0014187cc9cae2dbe46a

     文件        164  2015-05-16 14:13  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\1\b0c29b2b93fb001414aaadeef3ff8313

     文件       2237  2015-05-17 00:43  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\10\30b52e46ebfb0014103cc8b0f4f19749

     文件       1306  2015-05-16 02:31  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\10\f050a48f30fb00141b85b9eb67c4dc3b

     文件       1059  2015-05-16 01:23  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\11\5088c54427fb00141b85b9eb67c4dc3b

     文件       2815  2015-05-17 15:57  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\11\80ee0d6d6afc0014187cc9cae2dbe46a

     文件       2033  2015-05-15 15:26  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\11\909509d0d3fa0014139faef7eac0681d

     文件        585  2015-05-16 15:34  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\11\b09a45a1a0fb001414aaadeef3ff8313

     文件      10013  2015-05-17 17:55  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\11\b0b4210c7bfc0014187cc9cae2dbe46a

     文件       2168  2015-05-14 21:46  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\12\f03f11ad3ffa00141b90de9a89940249

     文件       4231  2015-05-17 23:04  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\14\10f0fe26a6fc0014187cc9cae2dbe46a

     文件       1832  2015-05-17 13:49  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\14\402259fd5efc0014187cc9cae2dbe46a

     文件       2653  2015-05-17 16:01  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\14\805d75f56afc0014187cc9cae2dbe46a

     文件        735  2015-05-16 01:26  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\14\c01dcf4a3afb00141b85b9eb67c4dc3b

     文件       2249  2015-05-15 15:57  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\15\408cd238d8fa0014139faef7eac0681d

     文件          0  2015-05-16 14:08  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\15\d028c40092fb001414aaadeef3ff8313

     文件       2024  2015-05-15 15:25  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\16\00c8c1bbd3fa0014139faef7eac0681d

     文件        584  2015-05-17 00:52  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\16\d02c7b50f0fb0014103cc8b0f4f19749

     文件      12905  2015-05-17 04:18  大作业--画图板\.metadata\.plugins\org.eclipse.core.resources\.history\16\e0b86dbd08fc0014103cc8b0f4f19749

............此处省略3156个文件信息

评论

共有 条评论