• 大小: 13KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-13
  • 语言: Java
  • 标签: java  画图板  

资源简介

用Java模拟画图板,实现基本图形的绘画,并支持撤销、清空、重复功能,可提供颜色选择。。。

资源截图

代码片段和文件信息

package lab14;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Myframe extends Jframe{
private JRadioButton linerectangleovalcurve;
private JRadioButton redblueblack;
private JButton jbt = new JButton(“Clear“);
private JButton undo = new JButton(“Undo“);
private JButton redo = new JButton(“Redo“);
private Paint paint = new Paint();  //画图的界面
private int type colorType;
private int x1x2y1y2;

public Myframe(){
JPanel jp1 = new JPanel();
jp1.setLayout(new GridLayout(101));
jp1.add(line = new JRadioButton(“Line“));
jp1.add(rectangle = new JRadioButton(“Rectangle“));
jp1.add(oval = new JRadioButton(“Oval“));
jp1.add(curve = new JRadioButton(“Curve“));
jp1.add(red = new JRadioButton(“Red“));
jp1.add(blue = new JRadioButton(“Blue“));
jp1.add(black = new JRadioButton(“Black“));
jp1.add(jbt);
jp1.add(undo);
jp1.add(redo);
ButtonGroup group1 = new ButtonGroup();
group1.add(line);
group1.add(rectangle);
group1.add(oval);
group1.add(curve);
ButtonGroup group2 = new ButtonGroup();
group2.add(red);
group2.add(blue);
group2.add(black);
setLayout(new BorderLayout());
add(jp1 BorderLayout.WEST);
add(paint BorderLayout.CENTER);

paint.addMouseListener(new PressListener());
paint.addMouseMotionListener(new DragListener());
line.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
type = 1;
}
});
rectangle.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
type = 2;
}
});
oval.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
type = 3;
}
});
curve.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
type = 4;
}
});
red.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
colorType = 1;
//paint.setColor(colorType);
}
});
blue.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
colorType = 2;
//paint.setColor(colorType);
}
});
black.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
colorType = 0;
//paint.setColor(colorType);
}
});
jbt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
paint.setIsClear(true);
paint.repaint();
paint.clear();
}
});
undo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
paint.undo();
paint.repaint();
}
});
redo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
paint.redo();
paint.repaint();
}
});
}

public static void main(String[] args){
Myframe frame = new Myframe();
frame.settitle(“Painter“);
frame.setLocationRelativeTo(null);
fr

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

     文件        232  2008-12-18 18:27  lab14\.classpath

     文件        381  2008-12-18 18:27  lab14\.project

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$1.class

     文件        744  2009-10-06 09:35  lab14\bin\lab14\Myframe$10.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$2.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$3.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$4.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$5.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$6.class

     文件        662  2009-10-06 09:35  lab14\bin\lab14\Myframe$7.class

     文件        788  2009-10-06 09:35  lab14\bin\lab14\Myframe$8.class

     文件        742  2009-10-06 09:35  lab14\bin\lab14\Myframe$9.class

     文件        981  2009-10-06 09:35  lab14\bin\lab14\Myframe$DragListener.class

     文件       1033  2009-10-06 09:35  lab14\bin\lab14\Myframe$PressListener.class

     文件       4150  2009-10-06 09:35  lab14\bin\lab14\Myframe.class

     文件       3990  2009-10-06 09:35  lab14\bin\lab14\Paint.class

     文件       3566  2008-12-18 23:26  lab14\src\lab14\Myframe.java

     文件       3949  2008-12-21 12:40  lab14\src\lab14\Paint.java

     目录          0  2009-10-06 09:35  lab14\bin\lab14

     目录          0  2008-12-18 18:28  lab14\src\lab14

     目录          0  2009-10-06 09:35  lab14\bin

     目录          0  2008-12-18 18:27  lab14\src

     目录          0  2008-12-18 18:27  lab14

----------- ---------  ---------- -----  ----

                25190                    23


评论

共有 条评论