java画板源代码

合集下载

java画板程序

java画板程序

简单的Java画板程序import java.awt.*;import java.awt.event.*;import java.awt.image.*;import java.io.*;import javax.imageio.*;import javax.swing.*;public class huaban{JFrame f=new JFrame("画板");//JPanel P1=new JPanel();//JPanel P2=new JPanel();JToolBar jtb=new JToolBar("工具");DrawCanvas drawArea=new DrawCanvas();int preX = -1;int preY = -1;int X=0;float con=1;int Econ=5;JButton btn0=new JButton(new ImageIcon("image/12.png"));//打开JButton btn1=new JButton(new ImageIcon("image/13.png"));//保存JButton btn2=new JButton(new ImageIcon("image/1.png"));//画笔JButton btn3=new JButton(new ImageIcon("image/2.png"));//直线//JButton btn4=new JButton("曲线");JButton btn5=new JButton(new ImageIcon("image/3.png"));//椭圆JButton btn6=new JButton(new ImageIcon("image/4.png"));//矩形JButton btn7=new JButton(new ImageIcon("image/7.png"));//调色板//JButton btn8=new JButton("当前颜色");JButton btn9=new JButton(new ImageIcon("image/14.png"));//橡皮JButton btn10=new JButton(new ImageIcon("image/6.png"));//清除JButton btn11=new JButton(new ImageIcon("image/8.png"));//黑色JButton btn12=new JButton(new ImageIcon("image/9.png"));//红色JButton btn13=new JButton(new ImageIcon("image/10.png"));//绿色JButton btn14=new JButton(new ImageIcon("image/11.png"));//蓝色JButton btn15=new JButton("1");//画笔大小JButton btn16=new JButton("2");JButton btn17=new JButton("3");JButton btn18=new JButton("4");JButton btn19=new JButton("1");//橡皮大小JButton btn20=new JButton("2");JButton btn21=new JButton("3");JButton btn22=new JButton("4");//JLabel L1=new JLabel("画笔颜色",JLabel.CENTER);JLabel L2=new JLabel("橡皮大小",JLabel.CENTER);JLabel L3=new JLabel("画笔大小",JLabel.CENTER);JLabel L4=new JLabel(" █",JLabel.CENTER);//当前颜色JLabel L5=new JLabel("当前颜色",JLabel.CENTER);//当前颜色FileDialog d1 = new FileDialog(f,"选择需要打开文件",FileDialog.LOAD);FileDialog d2 = new FileDialog(f,"选择保存文件的路径",FileDialog.SA VE);//Choice ColorChoice=new Choice();//Choice SizeChoice=new Choice();// Choice EraserChoice=new Choice();BasicStroke size = new BasicStroke(con);BufferedImage image = new BufferedImage(1366,768, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics();Graphics2D g2 = (Graphics2D)g;Color foreColor = new Color(0,0,0);public void init(){//P2.add(btn0);//P2.add(btn1);//P2.add(btn2);//P2.add(btn3);//P2.add(btn4);//P2.add(btn5);//P2.add(btn6);//P2.add(L1);//P2.add(ColorChoice);//P2.add(L3);//P2.add(SizeChoice);//P2.add(btn7);//P2.add(btn8);//P2.add(L4);//P2.add(btn9);//P2.add(L2);//P2.add(EraserChoice);//P2.add(btn10);jtb.add(btn0);jtb.add(btn1);jtb.addSeparator();jtb.add(btn2);jtb.add(btn3);jtb.add(btn5);jtb.add(btn6);jtb.add(btn9);jtb.addSeparator();jtb.add(btn11);jtb.add(btn12);jtb.add(btn13);jtb.add(btn14);jtb.add(btn7);jtb.addSeparator();//jtb.add(btn10);//jtb.addSeparator();jtb.add(L5);jtb.add(L4);jtb.addSeparator();jtb.add(L3);jtb.add(btn15);jtb.add(btn16);jtb.add(btn17);jtb.add(btn18);//jtb.add(SizeChoice);jtb.addSeparator();jtb.add(L2);jtb.add(btn19);jtb.add(btn20);jtb.add(btn21);jtb.add(btn22);//jtb.add(EraserChoice); jtb.addSeparator();jtb.add(btn10);//ColorChoice.add("black"); //ColorChoice.add("red"); //ColorChoice.add("green"); //ColorChoice.add("blue"); //SizeChoice.add("1");//SizeChoice.add("2");//SizeChoice.add("3");//SizeChoice.add("4");//EraserChoice.add("1");//EraserChoice.add("2");//EraserChoice.add("3");//EraserChoice.add("4");//P1.add(drawArea);//P2.setLayout(new GridLayout(1,1,5,5));//jtb.setOrientation(SwingConstants.VERTICAL);//jtb.setLayout(new GridLayout(8,2,2,2));//f.add(P2,BorderLayout.NORTH);f.add(jtb,BorderLayout.NORTH);//f.add(P1);//drawArea.setSize(500,500);f.add(drawArea);//drawArea.setBackground(Color.red);f.setSize(900,600);//P1.setSize(500,500);f.setV isible(true);g.setColor(Color.white);g.fillRect(0,0,1366,768);class A implements ActionListener{public void actionPerformed(ActionEvent e){if(e.getSource()==btn0){d1.setV isible(true);if(d1.getFile()!=null){try{File filein = new File(d1.getDirectory(),d1.getFile());Image srcImage=ImageIO.read(filein);g.drawImage(srcImage, 0 , 0 , null);drawArea.repaint();}catch(IOException IOe){System.out.println("can not read file");}}}else if(e.getSource()==btn1){d2.setV isible(true);if(d2.getFile()!=null){try{File fileout = new File(d2.getDirectory(),d2.getFile());ImageIO.write(image,"jpeg", fileout);}catch(IOException IOe){System.out.println("can not write file");}}}else if(e.getSource()==btn2){X=1;}else if(e.getSource()==btn3){X=2;}/*else if(e.getSource()==btn4){X=3;}*/else if(e.getSource()==btn5){X=4;}else if(e.getSource()==btn6){X=5;}else if(e.getSource()==btn7){foreColor = JColorChooser.showDialog(f,"选择画笔颜色",foreColor);L4.setForeground(foreColor);}/*else if(e.getSource()==btn8){}*/else if(e.getSource()==btn9){X=8;}else if(e.getSource()==btn10){g.setColor(Color.white);g.fillRect(0,0,1366,768);drawArea.repaint();X=0;}else if(e.getSource()==btn11){foreColor = new Color(0,0,0);L4.setForeground(foreColor);}else if(e.getSource()==btn12){foreColor = new Color(255,0,0);L4.setForeground(foreColor);}else if(e.getSource()==btn13){foreColor = new Color(0,255,0);L4.setForeground(foreColor);}else if(e.getSource()==btn14){foreColor = new Color(0,0,255);L4.setForeground(foreColor);}else if(e.getSource()==btn15){con=1;size = new BasicStroke(con);btn15.setForeground(Color.red);btn16.setForeground(Color.black);btn17.setForeground(Color.black);btn18.setForeground(Color.black); }else if(e.getSource()==btn16){con=3;size = new BasicStroke(con);btn16.setForeground(Color.red);btn15.setForeground(Color.black);btn17.setForeground(Color.black);btn18.setForeground(Color.black); }else if(e.getSource()==btn17){con=6;size = new BasicStroke(con);btn17.setForeground(Color.red);btn16.setForeground(Color.black);btn15.setForeground(Color.black);btn18.setForeground(Color.black); }else if(e.getSource()==btn18){con=9;size = new BasicStroke(con);btn18.setForeground(Color.red);btn16.setForeground(Color.black);btn17.setForeground(Color.black);btn15.setForeground(Color.black);}else if(e.getSource()==btn19){Econ=8;btn19.setForeground(Color.red);btn20.setForeground(Color.black);btn21.setForeground(Color.black);btn22.setForeground(Color.black);}else if(e.getSource()==btn20){Econ=14;btn20.setForeground(Color.red);btn19.setForeground(Color.black);btn21.setForeground(Color.black);btn22.setForeground(Color.black);}else if(e.getSource()==btn21){Econ=20;btn21.setForeground(Color.red);btn20.setForeground(Color.black);btn19.setForeground(Color.black);btn22.setForeground(Color.black);}else if(e.getSource()==btn22){Econ=26;btn22.setForeground(Color.red);btn20.setForeground(Color.black);btn21.setForeground(Color.black);btn19.setForeground(Color.black);}}}class B extends MouseMotionAdapter{// 实现按下鼠标键并拖动的事件处理器public void mouseDragged(MouseEvent e){if(X==1){// 设置当前颜色g.setColor(foreColor);g2.setStroke(size);// 绘制从上一次鼠标拖动事件点到本次鼠标拖动事件点的线段g.drawLine(preX , preY , e.getX() , e.getY());// 将当前鼠标事件点的X、Y坐标保存起来preX = e.getX();preY = e.getY();// 重绘drawArea对象drawArea.repaint();}if(X==8){g.setColor(Color.white);g.fillRect(e.getX(), e.getY(),Econ,Econ);drawArea.repaint();}}}class C extends MouseAdapter{public void mousePressed(MouseEvent e){preX = e.getX();preY = e.getY();}public void mouseReleased(MouseEvent e){if(X==2){// 设置当前颜色g.setColor(foreColor);g2.setStroke(size);// 绘制从上一次鼠标拖动事件点到本次鼠标拖动事件点的线段g.drawLine(preX , preY , e.getX() , e.getY());// 重绘drawArea对象drawArea.repaint();}if(X==4){// 设置当前颜色g.setColor(foreColor);g2.setStroke(size);g.drawOval(Math.min(preX,e.getX()),Math.min(preY,e.getY()),Math.abs(e.getX()-preX),Math.abs(e.getY()-preY));// 重绘drawArea对象drawArea.repaint();}if(X==5){// 设置当前颜色g.setColor(foreColor);g2.setStroke(size);g.drawRect(Math.min(preX,e.getX()),Math.min(preY,e.getY()),Math.abs(e.getX()-preX),Math.abs(e.getY()-preY));// 重绘drawArea对象drawArea.repaint();}}}/*class D extends MouseAdapter{ // 实现鼠标松开的事件处理器}*/class E extends WindowAdapter{public void windowClosing(WindowEvent e){System.exit(0);}}/*class F implements ItemListener{public void itemStateChanged(ItemEvent e){if(e.getSource()==EraserChoice){String Esize = EraserChoice.getSelectedItem();if(Esize=="1"){Econ=8;}else if(Esize=="2"){Econ=14;}else if(Esize=="3"){Econ=20;}else if(Esize=="4"){Econ=26;}}*//* else if(e.getSource()==ColorChoice){String name =ColorChoice.getSelectedItem();if(name=="black"){foreColor = new Color(0,0,0);L4.setForeground(foreColor);}else if(name=="red"){foreColor = new Color(255,0,0);L4.setForeground(foreColor);}else if(name=="green"){foreColor = new Color(0,255,0);L4.setForeground(foreColor);}else if(name=="blue"){foreColor = new Color(0,0,255);L4.setForeground(foreColor);}}*//* else if(e.getSource()==SizeChoice){String selected=SizeChoice.getSelectedItem();if(selected=="1"){con=1;size = new BasicStroke(con);}else if(selected=="2"){con=3;size = new BasicStroke(con);}else if(selected=="3"){con=6;size = new BasicStroke(con);}else if(selected=="4"){con=9;size = new BasicStroke(con);}}}}*/btn0.addActionListener(new A());btn1.addActionListener(new A());btn2.addActionListener(new A());btn3.addActionListener(new A());//btn4.addActionListener(new A());btn5.addActionListener(new A());btn6.addActionListener(new A());btn7.addActionListener(new A());//btn8.addActionListener(new A());btn9.addActionListener(new A());btn10.addActionListener(new A());btn11.addActionListener(new A());btn12.addActionListener(new A());btn13.addActionListener(new A());btn14.addActionListener(new A());btn15.addActionListener(new A());btn16.addActionListener(new A());btn17.addActionListener(new A());btn18.addActionListener(new A());btn19.addActionListener(new A());btn20.addActionListener(new A());btn21.addActionListener(new A());btn22.addActionListener(new A());//ColorChoice.addItemListener(new F());//SizeChoice.addItemListener(new F());//EraserChoice.addItemListener(new F()); drawArea.addMouseMotionListener(new B()); drawArea.addMouseListener(new C());//drawArea.addMouseListener(new D());f.addWindowListener(new E());}public static void main(String[] args){new huaban().init();}class DrawCanvas extends Canvas//JPanel {// 重写Canvas的paint方法,实现绘画public void paint(Graphics g){// 将image绘制到该组件上g.drawImage(image , 0 , 0 , null);}public void update(Graphics g){//g.setColor(Color.red);//g.fillRect(0,0,1366,768);paint(g);}}}14.png 13.png 12.png 11.png 10.png 9.png 8.png 7.png 6.png4.png 3.png 2.png 1.png。

JAVA画图板实现(基本画图功能+界面UI)二、功能实现及重绘实现

JAVA画图板实现(基本画图功能+界面UI)二、功能实现及重绘实现

JAVA画图板实现(基本画图功能+界⾯UI)⼆、功能实现及重绘实现上篇博客中介绍了界⾯的实现⽅法,在这篇博客中将对每个按钮的功能的实现进⾏讲解并介绍重绘⾸先肯定要添加事件监听机制了,那么问题来了,事件源对象是谁?需要添加什么⽅法?事件接⼝是什么?1、我们需要点击按钮,获取按钮上的⽂字信息,颜⾊信息,粗细信息。

那么,此时事件源对象就是按钮,监听⽅法就是addActionListener(ActionListener e),事件接⼝就是ActionListener2、要根据在窗体上按下和释放的位置画⼀个图形,此时事件源对象就是窗体,监听⽅法就是addMouseListener(MouseListener e),事件接⼝就是MouseListener1public class DrawListener extends MouseAdapter implements ActionListener {23private Color color = Color.black;// 声明颜⾊属性,存储⽤户选择的颜⾊4private int width = 1;// 声明粗细属性,存储⽤户选择的粗细5private String type = "Line";// 声明图形属性,存储⽤户选择的图形6private int x1, y1, x2, y2, x3 = 0, y3 = 0, x4 = 0, y4 = 0, x5, y5;// 声明坐标值属性,存储⿏标按下和释放的坐标值7private Graphics2D g;// 声明画笔类属性,组件是画出来的,现在要在组件上画图形,Graphics从组件上获取8private DrawMain dm;// 声明画图程序窗体组件属性9private JTextField text;// 获取⽂本框内容10private double H = 100;// 等腰三⾓形的⾼度11private int num = 0;12private List<Shape> list;13private ImageIcon i = new ImageIcon("C:\\Users\\long452a\\Desktop\\a1.jpg");1415/**16 * 构造⽅法17 *18 * @param dm画图程序的窗体组件对象19*/20public DrawListener(DrawMain dm, JTextField text, List<Shape> list) {21this.dm = dm;22this.text = text;23this.list = list;24 }2526/**27 * 点击按钮时执⾏的事件处理⽅法28 *29 * @param e对象中存储了事件源对象的信息和动作信息30*/31public void actionPerformed(ActionEvent e) {32 }3334/**35 * Invoked when the mouse button has been clicked (pressed and released) on a36 * component.37*/38public void mouseClicked(MouseEvent e) {39 }4041/**42 * Invoked when a mouse button has been pressed on a component.43*/44public void mousePressed(MouseEvent e) {45 }4647/**48 * Invoked when a mouse button has been released on a component.49*/50public void mouseReleased(MouseEvent e) {51 }5253public void mouseDragged(MouseEvent e) {54 }55 }这样我们的类就建好了,下⾯就该写⾥⾯的⽅法了1/**2 * 点击按钮时执⾏的事件处理⽅法3 *4 * @param e对象中存储了事件源对象的信息和动作信息5*/6public void actionPerformed(ActionEvent e) {7 String text = e.getActionCommand();8if (text.equals("")) {9 JButton button = (JButton) e.getSource();10 color = button.getBackground();11 } else if (text.equals("1") || text.equals("3") || text.equals("5")) {12 width = Integer.parseInt(text);13 } else {14 type = text;15 }16// System.out.println(color + ">>" + width + ">>" + type);17 }1819/**20 * Invoked when the mouse button has been clicked (pressed and released) on a21 * component.22*/23public void mouseClicked(MouseEvent e) {24 x4 = x2;25 y4 = y2;26 }2728/**29 * Invoked when a mouse button has been pressed on a component.30*/31public void mousePressed(MouseEvent e) {32 x1 = e.getX() + 7;33 y1 = e.getY() + 183;34if (y1 < 183)35 y1 = 183;36 g = (Graphics2D) dm.getGraphics();// 从窗体上获取画笔对象37 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 设置画笔抗锯齿38 g.setColor(color);// 设置画笔颜⾊39 g.setStroke(new BasicStroke(width));// 设置画笔线条粗细4041 }4243/**44 * Invoked when a mouse button has been released on a component.45*/46public void mouseReleased(MouseEvent e) {47 x2 = e.getX() + 7;48 y2 = e.getY() + 183;49if (y2 < 183)50 y2 = 183;51if (type.equals("iso_Tri")) {52if (x1 == x2) {53 g.drawLine(x1, y1, x2, y2);54 g.drawLine(x1, y1, x1 + (int) H, (y2 + y1) / 2);55 g.drawLine(x2, y2, x1 + (int) H, (y2 + y1) / 2);56 list.add(new Shape(x1, y1, x2, y2, width, color, type, i, dm, text));57 list.add(new Shape(x1, y1, x1 + (int) H, (y2 + y1) / 2, width, color, type, i, dm, text));58 list.add(new Shape(x2, y2, x1 + (int) H, (y2 + y1) / 2, width, color, type, i, dm, text));59 } else if (y1 == y2) {60 g.drawLine(x1, y1, x2, y2);61 g.drawLine(x1, y1, (x1 + x2) / 2, y1 + (int) H);62 g.drawLine(x2, y2, (x1 + x2) / 2, y1 + (int) H);63 list.add(new Shape(x1, y1, x2, y2, width, color, type, i, dm, text));64 list.add(new Shape(x1, y1, x1 + (x1 + x2) / 2, y1 + (int) H, width, color, type, i, dm, text));65 list.add(new Shape(x2, y2, x1 + (x1 + x2) / 2, y1 + (int) H, width, color, type, i, dm, text));66 } else {67double a = Math.atan((double) (x2 - x1) / (double) (y2 - y1));68double x3 = (double) (x1 + x2) / 2 + H * Math.cos(a);69double y3 = (double) (y1 + y2) / 2 - H * Math.sin(a);70 g.drawLine(x1, y1, x2, y2);71 g.drawLine(x1, y1, (int) x3, (int) y3);72 g.drawLine(x2, y2, (int) x3, (int) y3);73 list.add(new Shape(x1, y1, x2, y2, width, color, type, i, dm, text));74 list.add(new Shape(x1, y1, x1 + (int) x3, (int) y3, width, color, type, i, dm, text));75 list.add(new Shape(x2, y2, (int) x3, (int) y3, width, color, type, i, dm, text));76 }77 } else if (type.equals("Polygon")) {78if (num == 0) {79 g.drawLine(x1, y1, x2, y2);80 list.add(new Shape(x1, y1, x2, y2, width, color, type, i, dm, text));81 x5 = x2;82 y5 = y2;83 }84 num++;85if (num == 1) {86 x3 = x1;87 y3 = y1;88 }89if (x2 == x4 && y2 == y4) {90 g.drawLine(x1, y1, x3, y3);91 list.add(new Shape(x1, y1, x3, y3, width, color, type, i, dm, text));92 num = 0;93 } else {94 g.drawLine(x2, y2, x5, y5);95 list.add(new Shape(x2, y2, x5, y5, width, color, type, i, dm, text));96 x5 = x2;97 y5 = y2;98 }99 } else {100 Shape s = new Shape(x1, y1, x2, y2, width, color, type, i, dm, text);101 s.draw(g);102 list.add(s);103 }104 }105106public void mouseDragged(MouseEvent e) {107if (type.equals("Pencil")) {108 x2 = e.getX() + 7;//这⾥的+7 +183 是调出来的,能够使画的图是沿着⿏标109 y2 = e.getY() + 183;110if (y2 < 183)111 y2 = 183;112 Shape s = new Shape(x1, y1, x2, y2, width, color, type, i, dm, text);113 s.draw(g);114 list.add(s);115 x1 = x2;116 y1 = y2;117 } else if (type.equals("Erase")) {118 x2 = e.getX() + 7;119 y2 = e.getY() + 183;120if (y2 < 183)121 y2 = 183;122 Shape s = new Shape(x1, y1, x2, y2, width, Color.WHITE, type, i, dm, text);123 s.draw(g);124 list.add(s);125 x1 = x2;126 y1 = y2;127 } else if (type.equals("喷枪")) // 难点128 {129 Random rand = new Random();// 实例化⼀个随机数类的对象130int size = rand.nextInt(50);// 随机决定要画的点数131 x2 = e.getX() + 7;132 y2 = e.getY() + 183;133for (int j = 0; j < size; j++) {134// 在0-7之间可以取50次135int x = rand.nextInt(10);136int y = rand.nextInt(10);137// 不断改变(x1,y1)的坐标值,实现在(x1,y1)的周围画点138 Shape s = new Shape(x2 + x, y2 + y, x2 + x, y2 + y, width, color, type, i, dm, text); 139 s.draw(g);140 list.add(s);141 x1 = x2;142 y1 = y2;143 }144 }145 } 仔细看看代码,你也许注意到了,我在画图时创建了⼀个Shape对象,并且还把Shape对象存到了⼀个List中,为什么要这么做?你们可以去别⼈的博客上贴⼀个粗略实现的画图板代码,画⼏条直线然后再改变窗体的⼤⼩试试看,是不是画的直线不见了?那要怎么做才能使这些图形保存下来呢?这就需要⽤到重绘了。

java画图板程序源代码

java画图板程序源代码
ggg.setColor(g.getColor());
ggg.drawLine(p1.x,p1.y,p2.x,p2.y);
}
}
else if(橡皮擦通知==1&&清除通知==0)
{
g.setColor(getBackground());
g.fillRect(x-2,y-2,4,4);
ggg.fillRect(0,0,200,200);
}
g.drawImage(image,0,0,200,200,this);
}
public void mouseDragged(MouseEvent e)
{
x=(int)e.getX();
y=(int)e.getY();
Point p=new Point(x,y);
pSouth.add(清除);
pSouth.add(画笔);
window.add(pSouth,BorderLayout.SOUTH);
window.setVisible(true);
window.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
public void update(Graphics g)
{
{
paint(g);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==橡皮)
{
橡皮擦通知=1;
清除通知=0;

JAVA设计绘图软件(附源代码)

JAVA设计绘图软件(附源代码)

目录第一章选题简介 (3)第二章需求分析 (4)1.系统要实现的目标分析 (4)2.对输入输出数据及流程的分析 (4)3.开发环境及运行环境分析 (5)第三章系统设计 (6)1. 系统功能模块设计 (6)2. 类设计 (7)3. 界面设计 (8)第四章测试 (10)1.测试用例及结果 (10)2.程序功能的评价 (11)第五章总结 (12)1.遇到的问题及解决的方法 (12)2.开发体会及自评成绩 (12)参考文献 (13)第一章选题简介随着科学技术的不断提高,计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。

JAVA是一门很优秀的编程语言,具有面向对象、与平台无关、安全、稳定和多线程等特点,是目前软件设计中极为健壮的编程语言。

JAVA不仅可以用来开发大型的应用程序。

而且特别适合Internet的应用开发。

JAVA确实具备“一次写成,处处运行”的特点,JAVA以成为网络时代最重要的编程语言之一。

本次课程设计主要是用JAVA实现画笔系统,其系统主要完成以下功能:设计一个画图程序,能利用它实现用三种类型的线条在画板上任意绘画、书写的功能,该画图程序还需具有橡皮擦功能以及清空整个画面的功能。

第二章需求分析1.系统要实现的目标分析●这个画图程序,最基本的功能是,作为一个画笔,能利用它实现用三种类型的线条在画板上任意绘画、书写的功能;●这个画图程序,还需具备橡皮擦的功能,利用这个橡皮擦能够擦除画板上的图案;●这个画图程序,还应该具备能够清除整个画板已绘制图画的功能。

2.对输入输出数据及流程的分析3.开发环境及运行环境分析Jcreator是Xinox Software公司开发的一个用于Java程序设计的集成开发环境(IDE),具有编辑、调试、运行Java程序的功能。

当前最新版本是Jcreator5.00,它又分为LE和Pro版本。

LE版本功能上受到一些限制,是免费版本。

java 画板

java 画板

import java.awt.event.*;import java.awt.image.BufferedImage;import java.awt.*;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import javax.imageio.*;import javax.swing.*;public class myPaint extends JFrame implements ActionListener ,ItemListener{JLabel lb = new JLabel("画笔粗细:", JLabel.LEFT);JComboBox cb = new JComboBox();String size[] = { "1", "3", "5", "7", "9", "11", "13", "15", "17"};JLabel colorChooser = new JLabel("颜色:",JLabel.LEFT);JMenuBar mb = new JMenuBar();JMenu file = new JMenu("文件");JLabel appearance = new JLabel("形状:",JLabel.RIGHT);JMenu about = new JMenu("关于");JMenuItem open = new JMenuItem("打开");JMenuItem save = new JMenuItem("保存");JMenuItem off = new JMenuItem("退出");JButton curve = new JButton("曲线");JButton line = new JButton("直线");JButton circle = new JButton("椭圆");JButton rectangle = new JButton("矩形");JFileChooser chooser = new JFileChooser();static String iniPicName = ".\\ini.jpg";static File pic = new File(iniPicName);static int appChooser = 0;static int key = 0;static int fillKey = 0;static int serialNum = 0;static String fileName = ".\\ini.jpg";private String imageFormat = "jpg";Dimension d = Toolkit.getDefaultToolkit().getScreenSize();private myLabel board = new myLabel();private Label drawWidth = null;private Label drawCap = null;private ButtonColorAction buttonColorAction = null; private ButtonCursor buttonCursor = null;public myPaint() {super("标题");this.setJMenuBar(mb);mb.add(file);mb.add(appearance);file.add(open);file.add(save);file.add(off);appearance.add(curve);appearance.add(line);appearance.add(circle);appearance.add(rectangle);open.addActionListener(this);save.addActionListener(this);off.addActionListener(this);curve.addActionListener(this);line.addActionListener(this);rectangle.addActionListener(this);circle.addActionListener(this);for (int i = 0; i < 9; i++){cb.addItem(size[i]);}cb.setBackground(Color.white);cb.addItemListener(this);this.add(board);this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);}});setExtendedState(Frame.MAXIMIZED_BOTH);setLocation(15, 15);Panel pane = new Panel(new GridLayout(2, 1));Panel paneColor = new Panel(new GridLayout(1, 13));Button[] buttonColor = new Button[12];Color[] color = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.magenta, Color.orange,Color.pink, Color.red,Color.white, Color.yellow };paneColor.add(colorChooser);buttonColorAction = new ButtonColorAction();buttonCursor = new ButtonCursor();for (int i = 0; i < buttonColor.length; i++) {buttonColor[i] = new Button();buttonColor[i].setBackground(color[i]);buttonColor[i].addActionListener(buttonColorAction);buttonColor[i].addMouseListener(buttonCursor);paneColor.add(buttonColor[i]);}Panel appearance_pane = new Panel(new GridLayout(1, 7));drawWidth = new Label("3", Label.CENTER);drawCap = new Label("●", Label.CENTER);drawWidth.setBackground(Color.lightGray);drawCap.setBackground(Color.lightGray);appearance_pane.add(lb);appearance_pane.add(cb);appearance_pane.add(appearance);appearance_pane.add(curve);appearance_pane.add(line);appearance_pane.add(rectangle);appearance_pane.add(circle);pane.add(appearance_pane);pane.add(paneColor);this.add(pane, BorderLayout.SOUTH);this.add(board);this.setSize(1300,700);}public static void main(String arg[]) {new myPaint().setVisible(true);}public void actionPerformed(ActionEvent arg0) {// TODO Auto-generated method stubObject eventSource = arg0.getSource();if (eventSource == open) {chooser.setDialogTitle("打开文件");chooser.setApproveButtonText("打开");chooser.showOpenDialog(this);File file = chooser.getSelectedFile();if (file != null) {pic = file;try {myLabel.image = ImageIO.read(new FileInputStream(myPaint.pic));fileName = pic.toString();repaint();} catch (IOException e) {System.out.println("Error");}}}else if (eventSource == save){try {BufferedImage screenshot = (new Robot()).createScreenCapture(newRectangle(0, 0, (int) d.getWidth(), (int) d.getHeight()));serialNum++;String name = fileName + String.valueOf(serialNum) + "."+ imageFormat;File f = new File(name);System.out.print("Save File " + name);ImageIO.write(screenshot, imageFormat, f);System.out.print("..Finished!\n");}catch (Exception ex) {System.out.println(ex);}}else if (eventSource == off) {System.exit(0);} else if (eventSource == line) {appChooser = 1;key = 1;} else if (eventSource == rectangle) {appChooser = 2;key = 1;} else if (eventSource == circle) {appChooser = 3;key = 1;} else if (eventSource == curve) {appChooser = 0;key = 0;}}class ButtonColorAction implements ActionListener {public void actionPerformed(ActionEvent e) {Color color_temp = ((Button) e.getSource()).getBackground();board.setColor(color_temp);}}class ButtonCursor extends MouseAdapter {public void mouseEntered(MouseEvent e) {((Button) e.getSource()).setCursor(new Cursor(Cursor.HAND_CURSOR));}public void mouseExited(MouseEvent e) {((Button) e.getSource()).setCursor(new Cursor(Cursor.DEFAULT_CURSOR));}}public void itemStateChanged(ItemEvent e) {// TODO Auto-generated method stubif (e.getSource() == cb) {int i = 0;String str = (String) e.getItem();for (int j = 0; j < 9; j++)if (str == size[j])i = cb.getSelectedIndex();board.setStroke(new BasicStroke(i+2));}}}class myLabel extends JLabel implements MouseListener,MouseMotionListener {private int mouseX = 0;private int oldMouseX = 0;private int mouseY = 0;private int oldMouseY = 0;private int newMouseX = 0;private int newMouseY = 0;private int temMouseX = 0;private int temMouseY = 0;private int width = 0;private int height = 0;private Color color = null;private BasicStroke stroke = null;static BufferedImage image = null;public myLabel() {this.addMouseListener(this);this.addMouseMotionListener(this);color = new Color(0, 0, 0);stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);image = new BufferedImage(1300, 1024,BufferedImage.TYPE_INT_RGB);image.getGraphics().setColor(Color.white);image.getGraphics().fillRect(0, 0, 1280, 1024);try {image = ImageIO.read(new FileInputStream(myPaint.iniPicName));} catch (IOException e) {System.out.println("Error");}}/*** 重写paint 绘图方法*/public void paint(Graphics g) {Graphics2D g2d = (Graphics2D) g;Graphics2D bg = image.createGraphics();bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.V ALUE_ANTIALIAS_ON);bg.setColor(color);bg.setStroke(stroke);if ((newMouseX - temMouseX) >= 0) {width = newMouseX - temMouseX;if ((newMouseY - temMouseY) >= 0)height = newMouseY - temMouseY;else {height = temMouseY - newMouseY;if (myPaint.appChooser != 1)temMouseY = newMouseY;}} else {width = temMouseX - newMouseX;if ((newMouseY - temMouseY) >= 0) {height = newMouseY - temMouseY;if (myPaint.appChooser != 1)temMouseX = newMouseX;} else {height = temMouseY - newMouseY;if (myPaint.appChooser != 1) {temMouseY = newMouseY;temMouseX = newMouseX;}}}if (myPaint.key == 0) {if (myPaint.appChooser == 0)bg.drawLine(oldMouseX, oldMouseY, mouseX, mouseY);if (myPaint.appChooser == 1) {bg.drawLine(temMouseX, temMouseY, newMouseX, newMouseY);}if (myPaint.appChooser == 2) {bg.drawRect(temMouseX, temMouseY, width, height);}if (myPaint.appChooser == 3) {bg.drawOval(temMouseX, temMouseY, width, height);}}g2d.drawImage(image, 0, 0, this);}/*** 重写update 方法*/public void update(Graphics g) {this.paint(g);}public BasicStroke getStroke() {return stroke;}public void setStroke(BasicStroke stroke) {this.stroke = stroke;}public void setStroke(float width) {this.stroke = new BasicStroke(width, stroke.getEndCap(),stroke.getLineJoin());}public void setStroke(int cap) {this.stroke = new BasicStroke(stroke.getLineWidth(), cap,stroke.getLineJoin());}public Color getColor() {return color;}public void setColor(Color color) {this.color = color;}public void mouseClicked(MouseEvent mouseEvent) {}public void mousePressed(MouseEvent mouseEvent) {this.oldMouseX = this.mouseX = mouseEvent.getX();this.oldMouseY = this.mouseY = mouseEvent.getY();if (myPaint.appChooser != 0) {temMouseX = mouseX;temMouseY = mouseY;}if (myPaint.appChooser == 0 && myPaint.key == 0) {repaint();}}public void mouseReleased(MouseEvent mouseEvent) {if (myPaint.appChooser != 0) {newMouseX = mouseX;newMouseY = mouseY;myPaint.key = 0;repaint();}}public void mouseEntered(MouseEvent mouseEvent) {this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));}public void mouseExited(MouseEvent mouseEvent) {this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));}public void mouseDragged(MouseEvent mouseEvent) {this.oldMouseX = this.mouseX;this.oldMouseY = this.mouseY;this.mouseX = mouseEvent.getX();this.mouseY = mouseEvent.getY();if (myPaint.appChooser == 0 && myPaint.key == 0) {repaint();}}public void mouseMoved(MouseEvent mouseEvent) {}}。

java课程设计画图完整源码

java课程设计画图完整源码

java课程设计画图完整源码一、教学目标本章节的教学目标是使学生掌握Java编程语言的基本知识,能够使用Java编写简单的图形用户界面程序。

具体目标如下:1.知识目标:–了解Java编程语言的基本语法和结构。

–掌握面向对象编程的基本概念和方法。

–了解Java图形用户界面编程的基本原理和常用组件。

2.技能目标:–能够使用Java编写简单的控制台程序。

–能够使用Java编写简单的图形用户界面程序。

–能够阅读和理解Java代码。

3.情感态度价值观目标:–培养学生的编程兴趣和自信心,使其能够主动学习编程知识。

–培养学生的问题解决能力和创新精神,使其能够通过编程解决实际问题。

二、教学内容本章节的教学内容主要包括Java编程语言的基本语法和结构、面向对象编程的概念和方法、Java图形用户界面编程的基本原理和常用组件。

具体内容如下:1.Java编程语言的基本语法和结构:–数据类型、变量和常量–运算符和表达式–控制语句(条件语句、循环语句)–函数和数组2.面向对象编程的概念和方法:–类和对象的概念–构造函数和析构函数–封装、继承和多态的概念和应用3.Java图形用户界面编程的基本原理和常用组件:–图形用户界面编程的基本原理和框架–常用组件(按钮、文本框、标签等)的使用和属性设置–事件处理和用户输入三、教学方法本章节的教学方法采用讲授法和实验法相结合的方式。

首先通过讲授法向学生介绍Java编程语言的基本语法和结构、面向对象编程的概念和方法、Java图形用户界面编程的基本原理和常用组件。

然后通过实验法让学生亲自动手编写代码,实践所学的知识,并通过实验过程中遇到的问题引导学生思考和解决问题。

四、教学资源本章节的教学资源包括教材、参考书、多媒体资料和实验设备。

教材和参考书用于提供理论知识和编程技巧,多媒体资料用于辅助讲解和演示,实验设备用于学生动手实践。

教师需要根据学生的实际情况和教学要求选择和准备相应的教学资源,以支持教学内容和教学方法的实施,丰富学生的学习体验。

java图形界面代码

java图形界面代码

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.text.*;public class JTextFieldDemo2 {JFrame frame=new JFrame("JTextField Demo2");JLabel nameLabel=new JLabel("User Name");JLabel pwLabel=new JLabel("Password");JTextField nameField=new JTextField();JPasswordField pwField=new JPasswordField();JTextArea ta=new JTextArea(5,20);public static void mian(String args[]){JTextFieldDemo2 tfd2=new JTextFieldDemo2();tfd2.go();}public void go(){UpperCaseDocument ucDocument=new UpperCaseDocument();nameField.setDocument(ucDocument);nameField.setForeground(Color.red);nameField.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String username=nameField.getText();//获取文本域的内容ta.append("\nUser Name:"+username);//显示在文本区中}});pwField.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){char[] pw=pwField.getPassword();String password=new String(pw);ta.append("\nPassword:"+password);}});JPanel labelPanel=new JPanel();labelPanel.setLayout(new GridLayout(2,1));labelPanel.add(nameField);labelPanel.add(pwLabel);JPanel fieldPanel=new JPanel();fieldPanel.setLayout(new GridLayout(2,1));fieldPanel.add(nameField);fieldPanel.add(pwField);JPanel northPanel=new JPanel();northPanel.setLayout(new GridLayout(1,2));northPanel.add(labelPanel);northPanel.add(fieldPanel);JScrollPane jsp=new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);Container cp=frame.getContentPane();cp.add(northPanel,BorderLayout.NORTH);cp.add(jsp,BorderLayout.CENTER);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.pack();frame.setVisible(true);}}class UpperCaseDocument extends PlainDocument{public void insertString(int offset,String string,AttributeSet attributeSet)throws BadLocationException{string=string.toUpperCase();super.insertString(offset,string,attributeSet);}}。

JAVA画图板程序实验报告(附完整代码)资料

JAVA画图板程序实验报告(附完整代码)资料

画板程序一、软件系统分析和设计方案1、功能需求分析设计类似于Windows画板的程序,程序可以通过功能菜单(或工具条)进行功能选择操作,在画板中可以用鼠标操作绘制不同颜色的点,直线,多边形和椭圆,可以保存和打开自定义的图形文件。

2、结构设计过程经过对需求的分析,我们设计的画图板界面主要包括菜单栏、工具栏、画板三个部分。

菜单栏包含文件、编辑、帮助等常见功能菜单,实现打开保存文件等功能;工具栏主要包括画笔、矩形、椭圆、直线、刷子、橡皮、文字、颜色等工具,可完成一些基本操作;画板能够编辑处理图片及文字。

而代码实现上采用面向对象的思想,将上述组件封装与一个画板类中布局并实现功能;通过一个窗框类实现画板对象;最后在主类中建立窗框对象。

思路如下图:二、软件实现和代码编写具体代码及详细注释如下:import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import javax.swing.*;import javax.swing.UIManager.*;import java.io.*;import java.util.Vector;//主类建立窗框public class DrawPad {public static void main(String[] args) {try {// 优化UI效果for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) {UIManager.setLookAndFeel(info.getClassName());break;}}} catch (Exception e) {System.out.println(e);}new DrawFrame();}}// 添加窗口和画板组件class DrawFrame extends JFrame {public DrawFrame() {DrawPanel panel = new DrawPanel();add(panel);setTitle("简单JAVA画板");setBounds(100, 100, 800, 600);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}// 定义绘画点的基本属性class position implements Serializable {int x;int y;int type;String s;Color color;}// 定义画板组件class DrawPanel extends JPanel implements ActionListener, MouseListener, MouseMotionListener {JMenuBar mb;// 菜单栏JMenu menu1, menu2, menu3;JMenuItem i1, i2, i3, i4;JPanel jp1; // 工具栏public JButton anj0, anj1, anj2, anj3, anj4, anj5, anj6, anj7, anj8, anj9,anj10;JLabel l1, lcolor;Vector<position> thedraw = new Vector<position>(); // 保存画图轨迹的数组int style = 0; // 保存画图类型,默认为画笔int x1 = 0;// 保存点的坐标int x2 = 0;int y1 = 0;int y2 = 0;String input = "";// 默认输入文字内容Color linecolor = Color.BLACK; // 默认线的颜色public DrawPanel() {setBackground(Color.WHITE);setLayout(new BorderLayout());setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));// 上部菜单栏mb = new JMenuBar();mb.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));add(mb, BorderLayout.NORTH);// 加入菜单栏的组件menu1 = new JMenu(" 文件");menu2 = new JMenu(" 编辑");menu3 = new JMenu(" 帮助");i1 = new JMenuItem("打开", new ImageIcon("img/open.png"));i2 = new JMenuItem("保存", new ImageIcon("img/save.png"));i3 = new JMenuItem("清空", new ImageIcon("img/clear.png"));i4 = new JMenuItem("关于简单JAVA画板", new ImageIcon( "img/about.png"));menu1.add(i1);menu1.addSeparator();menu1.add(i2);menu2.add(i3);menu3.add(i4);mb.add(menu1);mb.add(menu2);mb.add(menu3);add(mb, BorderLayout.NORTH);// 侧边工具栏jp1 = new JPanel();jp1.setBackground(Color.LIGHT_GRAY);jp1.setLayout(new BoxLayout(jp1, BoxLayout.Y_AXIS));jp1.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));add(jp1, BorderLayout.WEST);// 加入工具栏的组件anj0 = new JButton("画笔", new ImageIcon("img/pen.png"));anj1 = new JButton("刷子", new ImageIcon("img/brush.png"));anj2 = new JButton("橡皮", new ImageIcon("img/erease.png"));anj3 = new JButton("文字", new ImageIcon("img/word.png"));anj4 = new JButton("直线", new ImageIcon("img/sline.png"));anj5 = new JButton("矩形", new ImageIcon("img/rec.png"));anj6 = new JButton("圆矩", new ImageIcon("img/frec.png"));anj7 = new JButton("椭圆", new ImageIcon("img/eli.png"));anj10 = new JButton("");lcolor = new JLabel("■");// 会变色的方块l1 = new JLabel(" 颜色");anj10.add(lcolor);anj10.add(l1);jp1.add(anj0);jp1.add(anj1);jp1.add(anj2);jp1.add(anj3);jp1.add(anj4);jp1.add(anj5);jp1.add(anj6);jp1.add(anj7);jp1.add(anj10);// 事件处理i1.addActionListener(this);i2.addActionListener(this);i3.addActionListener(this);i4.addActionListener(this);anj0.addActionListener(this);anj1.addActionListener(this);anj2.addActionListener(this);anj3.addActionListener(this);anj4.addActionListener(this);anj5.addActionListener(this);anj6.addActionListener(this);anj7.addActionListener(this);anj10.addActionListener(this);addMouseListener(this);addMouseMotionListener(this);}// 记录鼠标选择的功能public void actionPerformed(ActionEvent e) {if (e.getSource() == anj0)style = 0;else if (e.getSource() == anj1)style = 1;else if (e.getSource() == anj2)style = 2;else if (e.getSource() == anj3) {style = 3;input = JOptionPane.showInputDialog("输入文字后在画板上点击放置");} else if (e.getSource() == anj4)style = 4;else if (e.getSource() == anj5)style = 5;else if (e.getSource() == anj6)style = 6;else if (e.getSource() == anj7)style = 7;else if (e.getSource() == anj10) {linecolor = JColorChooser.showDialog(null, "请选择颜色", Color.BLACK);lcolor.setForeground(linecolor);} else if (e.getActionCommand().equals("关于简单JAVA画板")) {JOptionPane.showMessageDialog(null,"这是一个简单的JAVA画板。

用java实现的一个简单的画板程序

用java实现的一个简单的画板程序

用java实现的一个简单的画板程序一个实现简单画板功能的java程序,可以画直线,长方形,椭圆,曲线。

主类import java.awt.Color;import javax.swing.*;public class painter {public static void main(String [] args){JPanel jpl = new Board();JFrame painter =new JFrame();painter.add(jpl);painter.setBackground(Color.WHITE);painter.setTitle("Painter");painter.setSize(400,200);painter.setLocationRelativeTo(null);painter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);painter.setVisible(true);}}加了选择事件的画板import java.awt.*;import javax.swing.*;import java.awt.event.*;@SuppressWarnings("serial")public class Choose extends Board{JRadioButton jrb1=new JRadioButton("Line");JRadioButton jrb2=new JRadioButton("Rectangle");JRadioButton jrb3=new JRadioButton("Oval");JRadioButton jrb4=new JRadioButton("Curve");JButton jbt = new JButton("Clear");public Choose(){JPanel jp1=new JPanel();jp1.setLayout(new GridLayout(5,1,5,5));jp1.add(jrb1);jp1.add(jrb2);jp1.add(jrb3);jp1.add(jrb4);jp1.add(jbt);add(jp1);ButtonGroup group = new ButtonGroup();group.add(jrb1);group.add(jrb2);group.add(jrb3);group.add(jrb4);ActionListener chooseListener = new chooseListener(); MouseListener clearListener = new clearListener();jrb1.addActionListener(chooseListener);jrb2.addActionListener(chooseListener);jrb3.addActionListener(chooseListener);jrb4.addActionListener(chooseListener);jbt.addMouseListener(clearListener);}class chooseListener implements ActionListener{ public void actionPerformed(ActionEvent e) {if(e.getSource()==jrb1){drawLine();System.out.println("line");}else if(e.getSource()==jrb2){drawRectangle();System.out.println("rec");}else if(e.getSource()==jrb3){drawOval();System.out.println("oval");}else if(e.getSource()==jrb4){drawCurve();System.out.println("curve");}}}class clearListener extends MouseAdapter{public void mouseClicked(MouseEvent e){ drawClear();}}}画板import java.awt.*;import java.awt.event.*;import java.awt.image.BufferedImage;import java.awt.image.ImageProducer;import javax.swing.*;@SuppressWarnings("serial")public class Board extends JPanel{ JRadioButton jrb1=new JRadioButton("Line"); JRadioButton jrb2=new JRadioButton("Rectangle"); JRadioButton jrb3=new JRadioButton("Oval");JRadioButton jrb4=new JRadioButton("Curve");JButton jbt = new JButton("Clear");BufferedImage bi=new BufferedImage(500,500,BufferedImage.TYPE_INT_RGB);;int x=-1;int y=-1;int [] location=new int[4];int mode=0;boolean ifNotCurveClicked=false;boolean ifCurveClicked=false;public Board(){setLayout(new BorderLayout());JPanel jp1=new JPanel();jp1.setLayout(new GridLayout(5,1,5,5));jp1.add(jrb1);jp1.add(jrb2);jp1.add(jrb3);jp1.add(jrb4);jp1.add(jbt);add(jp1,BorderLayout.WEST);ButtonGroup group = new ButtonGroup();group.add(jrb1);group.add(jrb2);group.add(jrb3);group.add(jrb4);ActionListener chooseListener = new chooseListener();MouseListener clearListener = new clearListener();jrb1.addActionListener(chooseListener);jrb2.addActionListener(chooseListener);jrb3.addActionListener(chooseListener);jrb4.addActionListener(chooseListener); jbt.addMouseListener(clearListener);}public void drawLine(){ addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ location[0]=e.getX();location[1]=e.getY();}public void mouseReleased(MouseEvent e){ if(!ifCurveClicked){location[2]=e.getX();location[3]=e.getY();mode=1;repaint();}}});}public void drawRectangle(){ addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ location[0]=e.getX();location[1]=e.getY();}public void mouseReleased(MouseEvent e){ if(!ifCurveClicked){location[2]=e.getX();location[3]=e.getY();mode=2;repaint();}}});}public void drawOval(){ addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ location[0]=e.getX();location[1]=e.getY();}public void mouseReleased(MouseEvent e){if(!ifCurveClicked){location[2]=e.getX();location[3]=e.getY();mode=3;repaint();}}});}public void drawCurve(){ addMouseMotionListener(new MouseAdapter(){ public void mouseDragged(MouseEvent e){if(!ifNotCurveClicked){x=e.getX();y=e.getY();mode=4;repaint();}}});}public void drawClear(){mode=5;repaint();}protected void paintComponent(Graphics g){switch(mode){case(1):g.drawLine(location[0],location[1],location[2],location[3]);break;case(2):if(location[0]<=location[2]&&location[1]<location[3])<p="">g.drawRect(location[0],location[1],location[2]-location[0],location[3]-location[1]);else if(location[0]<=location[2]&&location[1]>=location[3])g.drawRect(location[0],location[3],location[2]-location[0],location[1]-location[3]);else if(location[0]>location[2]&&location[1]<=location[3])g.drawRect(location[2],location[1],location[0]-location[2],location[3]-location[1]);elseg.drawRect(location[2],location[3],location[0]-location[2],location[1]-location[3]);break;case(3):if(location[0]<=location[2]&&location[1]<location[3])<p="">g.drawOval(location[0],location[1],location[2]-location[0],location[3]-location[1]);else if(location[0]<=location[2]&&location[1]>=location[3])g.drawOval(location[0],location[3],location[2]-location[0],location[1]-location[3]);else if(location[0]>location[2]&&location[1]<=location[3])g.drawOval(location[2],location[1],location[0]-location[2],location[3]-location[1]);elseg.drawOval(location[2],location[3],location[0]-location[2],location[1]-location[3]);break;case(4):g.fillOval(x,y,2,2);break;case(5):setBackground(Color.WHITE);super.paintComponent(g);break;}}class chooseListener implements ActionListener{public void actionPerformed(ActionEvent e) {if(e.getSource()==jrb1){ifNotCurveClicked=true;ifCurveClicked=false;drawLine();}else if(e.getSource()==jrb2){ifNotCurveClicked=true;ifCurveClicked=false;drawRectangle();}else if(e.getSource()==jrb3){ ifNotCurveClicked=true; ifCurveClicked=false;drawOval();}else if(e.getSource()==jrb4){ ifNotCurveClicked=false; ifCurveClicked=true;drawCurve();}}}class clearListener extends MouseAdapter{ public void mouseClicked(MouseEvent e){ drawClear();}}}</location[3])<></location[3])<>。

画图java课程设计源代码

画图java课程设计源代码

画图 java课程设计源代码一、教学目标本节课的教学目标是让学生掌握Java编程中的画图功能,理解并能够运用Java语言实现简单的图形绘制。

具体来说,知识目标包括了解Java画图的基本概念和API,理解图形绘制的基本原理;技能目标包括能够独立完成Java画图程序的编写,熟练使用Java语言进行图形绘制;情感态度价值观目标包括培养学生的创新意识,提高学生对计算机编程的兴趣。

二、教学内容本节课的教学内容主要包括Java画图的基本概念、API的使用以及图形绘制的基本原理。

首先,将介绍Java画图的基本概念,让学生了解什么是画图以及画图的应用场景。

然后,将讲解Java画图的API,包括如何使用Java语言进行图形绘制,如何设置图形的颜色、形状等属性。

接下来,将通过实例演示的方式,让学生亲自动手实践,加深对Java画图的理解。

最后,将总结本节课的内容,并进行课堂提问,检查学生对Java画图的掌握情况。

三、教学方法为了达到本节课的教学目标,将采用讲授法、讨论法和实验法等多种教学方法。

首先,通过讲授法向学生传授Java画图的基本概念和API使用方法。

然后,通过讨论法让学生互相交流、讨论在实践过程中遇到的问题和解决方法,促进学生的思考和合作。

接着,通过实验法让学生亲自动手操作,实践Java画图的编写和绘制,增强学生的实践能力。

四、教学资源为了支持本节课的教学内容和教学方法的实施,将准备教材、参考书、多媒体资料和实验设备等教学资源。

教材和参考书将提供Java画图的基本概念和API的详细介绍,帮助学生理解和掌握相关知识。

多媒体资料将通过图像、视频等形式展示Java画图的实例,丰富学生的学习体验。

实验设备将用于让学生亲自动手实践,培养学生的实际操作能力。

五、教学评估本节课的教学评估将采用多元化的评估方式,以全面、客观、公正地评价学生的学习成果。

评估方式包括平时表现、作业和考试三个部分。

平时表现将根据学生在课堂上的参与度、提问回答、小组讨论等表现进行评估。

java画板源代码

java画板源代码
Color c1=Color.white; ///设置按钮背景颜色
int f = 1;
int sx, sy, x, y; //坐标记录
boolean fill = false;
boolean flag = false;
JScrollBar r1 = new JScrollBar(JScrollBar.HORIZONTAL, 251, 4, 0, 255); //横向滚动条,初始值,扩展大小,最小值,最大值
}
public void mouseMoved(MouseEvent e) {
}
/**
* Dragged()都是最终不实现的,使用XOR只展现过程曲线
*最终都会小时,真正实现“画出来”的是Release()
*/
public void mouseDragged(MouseEvent e) {
int x0, y0;
Image icon = Toolkit.getDefaultToolkit().getImage("src\\huaban\\picture\\c6.jpg");
frame.setIconImage(icon);
getContentPane().setLayout(new BorderLayout()); //边界布局
g.drawLine(sx, sy, x, y);
//开始覆盖
x = e.getX();
y = e.getY();
break;
case 3:
case 4:
x = e.getX();
y = e.getY();
x0 = x > sx ? sx : x;
y0 = y > sy ? sy : y;

java编写的画图板

java编写的画图板

1.import java.applet.*;2.import java.awt.*;3.import java.awt.event.*;4.import java.util.*;5.import javax.swing.*;6.import java.awt.geom.*;7.import java.io.*;8.9.class Point implements Serializable//Object serialization 允许你将实现了Serializable接口10.11.// 的对象转换为字节序列,这些字节序列可以被完全存储以备以后重新生成原来的对象。

12.{13.int x,y;14. Color col;15.int tool;16.int boarder;17.18. Point(int x, int y, Color col, int tool, int boarder)19. {20.this.x = x;21.this.y = y;22.this.col = col;23.this.tool = tool;24.this.boarder = boarder;25. }26.}27.28.29.class paintboard extends Frame implements ActionListener,MouseMotionListener,MouseListener,ItemListener30.//Java中Frame默认的布局管理器为BorderLayout,加一个TextField到BorderLayout.SOUTH用来查看31.32.//点击菜单的getSource()和getCommand()信息,接口 java.awt.event.MouseMotionListener33.34.//public interface MouseMotionListener extends EventListener35.36.//用于接收组件上的鼠标移动事件的监听者接口。

java实现画图板功能

java实现画图板功能

java实现画图板功能本⽂实例为⼤家分享了java实现画图板的具体代码,供⼤家参考,具体内容如下画图板需要满⾜的功能有:画线,画三⾓形,画矩形,画多边形,画曲线设置不同颜⾊的画笔改变窗⼝⼤⼩或最⼩化窗⼝后重新打开时图案不消失画图⽅法的编写:创建⼀个类,继承JPanel类,重写JPanel的绘制⽅法,重写⽅法时写上原有的绘制⽅法,再添加绘制已有的图形的⽅法。

(为了在改变窗⼝⼤⼩和最⼩化窗⼝后再打开时图案不消失)在画图⽅法中⾸先创建⼀个窗体,设置好各项参数后,将窗体设置边框布局。

由于继承了JPanel类,重写的JPanel的绘制⽅法对于this⽣效,所以this为画图部分的⾯板,将this设置背景⾊为⽩⾊,添加到边框布局的中央。

再创建⼀个⾯板对象(此⾯板对象⽤于存放按钮),设置⼀个背景⾊并放在边框布局的上⽅。

由于接下来的按钮和画图⾯板都需要监听器,于是创建Listener类。

Listener类实现ActionListener,MouseListener,MouseMotionListener的接⼝。

Listener类需要重写这些监听器接⼝的所有⽅法。

创建字符串数组存放画图形状的名称,接着使⽤for循环,将字符串添加到各个按钮上,再将按钮添加到⾯板对象中,最后再给按钮加上按钮监听器;接着再创建颜⾊类的数组存放各种颜⾊,同样使⽤for循环,将颜⾊设置成按钮的背景⾊,再将按钮添加到边框布局上⽅的⾯板对象中,再给按钮添加监听器。

最后再在⾯板上获取画笔并添加上⿏标监听器。

package draw0924;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;public class drawframe extends JPanel{public static void main(String[] args) {drawframe dr=new drawframe();dr._draw();}private Shape[] shape;public void _draw() {JFrame jf=new JFrame();jf.setSize(800,800);jf.setTitle("画图窗⼝");jf.setLocationRelativeTo(null);jf.setDefaultCloseOperation(3);jf.setLayout(new BorderLayout());//设置边框布局JPanel panel=new JPanel();//创建⼀个⾯板对象panel.setBackground(Color.GREEN);jf.add(panel,BorderLayout.NORTH);//添加到边框布局的上⽅Listener butt=new Listener();//创建监听器类,并创建⼀个监听器对象String[] str= {"画线","画三⾓形","画矩形","画多边形","画曲线"};//创建字符串数组存储按钮⽂字for(int i=0;i<str.length;i++) {JButton jbu=new JButton(str[i]);//创建按钮对象并把按钮⽂字添加上panel.add(jbu);//将按钮添加到⾯板对象上jbu.addActionListener(butt);//给按钮添加监听器}Color[] color= {Color.RED,Color.BLUE,new Color(104,150,144)};//创建颜⾊数组存储画笔颜⾊for(int i=0;i<color.length;i++) {JButton jbu=new JButton();//创建按钮对象jbu.setBackground(color[i]);//将按钮背景设置颜⾊panel.add(jbu);//将按钮添加到⾯板对象上jbu.setPreferredSize(new Dimension(30,30));//设置按钮⼤⼩jbu.addActionListener(butt);//给按钮添加监听器}this.setBackground(Color.WHITE);//将继承来的⾯板设置背景⾊jf.add(this,BorderLayout.CENTER);//将此⾯板添加到边框布局的中央jf.setVisible(true);Graphics g=this.getGraphics();//在要绘画的⾯板上获取画笔(要在窗⼝可视化之后)butt.setg(g);//将画笔传⼊监听器this.addMouseListener(butt);//给要绘画的⾯板添加⿏标监听器this.addMouseMotionListener(butt);//给要绘制的⾯板添加⿏标监听器shape=butt.get();//将监听器内保存的图形保存到此类的全局变量中}public void paint(Graphics g) {super.paint(g);//⽗类的绘画⽅法for(int i=0;i<shape.length;i++) {if(shape[i]!=null) {shape[i].drawshape(g);//图形的绘画}}}}监听器⽅法的重写:⾸先是点击按钮监听⽅法的重写:获取按钮上的字符串,如果是空字符串则将监听器内的画笔颜⾊设置为按钮颜⾊,如果是绘图⽅法的字符串(⽤于以下的监听⽅法中判断执⾏绘画⽅法),并将全局变量i重置为0(在切换画图⽅法时可重置数据)。

JAVA简单画板程序设计实验报告(可打印修改)

JAVA简单画板程序设计实验报告(可打印修改)
public void mousePressed(MouseEvent e) { x0=e.getX(); y0=e.getY();
}
b. 鼠标移动事件
public void mouseMoved(MouseEvent e){ }
c. 鼠标按钮松开事件,此次响应完成对直线,椭圆,矩形进
行绘制。
public void mouseReleased(MouseEvent e) {
调用choice1.getSelectedItem()返回被选中选项的标签
文本字符串,即确定画笔的大小(con)。
5. 工具栏工具实现程序详解
(1)Graphics2D g = (Graphics2D)this.getGraphics();
size=newBasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN _BEVEL); g.setColor(b); g.setStroke(size);
路径和虚线线段,JOIN_BEVEL通过直线连接宽体轮廓的
外角,将路径线段连接在一起。(以上内容为网上查找资
料所得。)
(2) 实现直线,椭圆,矩形绘制:
switch(a) { case '1': g.drawLine(x0, y0, e.getX(), e.getY()); break; case '2': g.drawOval(x0, y0, e.getX() - x0, e.getY() - y0); break; case '3': g.drawRect(x0, y0, e.getX() - x0, e.getY() - y0); break;
6. 主类 程序得以运行的入口,进入主类后即运行litao()类。 C. 调试运行 调试运行后得到了画板和预期的所有功能,实现结果展示:

Java实现简易画图板

Java实现简易画图板

Java实现简易画图板本⽂实例为⼤家分享了Java实现简易画图板的具体代码,供⼤家参考,具体内容如下这是Windows系统⾃带的画图板,我们就是模仿着⽤Java去写⼀个简易版的画图板。

效果图图中的四个颜⾊按钮是可以配合要画的图形⽽改变线条颜⾊的,⽽且每次打开颜⾊按钮的颜⾊都是随机的。

⽬前画图什么的都没什么问题,只是⼀些细节没有去完全修复了,但不影响使⽤,再加上近段时间有点太忙,就没有去完善相关细节了,有兴趣的⼩伙伴可以评论区帮忙提出指正意见哈。

画图板UI界⾯代码import java.awt.Color;import java.awt.Dimension;import java.awt.FlowLayout;import javax.swing.JButton;import javax.swing.JFrame;import java.awt.Graphics;import java.util.Random;public class DrawGraphics {Random rand=new Random();public static void main(String []args){DrawGraphics draw=new DrawGraphics();draw.displayUI();}public JButton getButton(String s,DrawListener dl,boolean flag){JButton btn=new JButton();//每个按钮的尺⼨Dimension dim=new Dimension(200,50);//如果flag为true,创建⽂字按钮,否则创建颜⾊按钮if(flag){btn=new JButton(s);}else{Color c= new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256));btn.setBackground(c);}btn.setPreferredSize(dim);btn.addActionListener(dl);return btn;}public void displayUI(){JFrame frame=new JFrame();FlowLayout f1=new FlowLayout();frame.setTitle("画图板");frame.setSize(1000,1000);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setLocationRelativeTo(null);frame.setLayout(f1);frame.setResizable(false);DrawListener dl=new DrawListener();String []name={"直线","矩形","圆","三⾓形"};for(int i=0;i<name.length;i++){frame.add(getButton(name[i],dl,true));}for(int i=0;i<name.length;i++){frame.add(getButton("",dl,false));}frame.addMouseListener(dl);frame.setVisible(true);// 获取画笔 --- 必须要放在可视化之后Graphics g=frame.getGraphics();dl.g=g;dl.btnstr=name[0];=name;}}画图板UI监听器代码import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JButton;import java.awt.Color;import java.awt.Graphics;public class DrawListener implements MouseListener,ActionListener{ Graphics g;int x1,x2,y1,y2;int x3,x4,x5,y3,y4,y5;int count=0;String []name;String btnstr;int i;@Overridepublic void actionPerformed(ActionEvent e) {btnstr=e.getActionCommand();if(btnstr.equals("")){JButton btn=(JButton)e.getSource();Color btnColor=btn.getBackground();g.setColor(btnColor);}else {for(i=0;i<name.length;i++){if(btnstr.equals(name[i]))break;}}}@Overridepublic void mouseClicked(MouseEvent e) {if(btnstr.equals(name[3])||btnstr.equals("")){g.drawOval(e.getX()-4, e.getY()-4, 8, 8);if(count==0){x3=e.getX();y3=e.getY();count++;}else if(count==1){x4=e.getX();y4=e.getY();g.drawLine(x3, y3, x4, y4);count++;}else if(count==2){x5=e.getX();y5=e.getY();g.drawLine(x3, y3, x5, y5);g.drawLine(x4, y4, x5, y5);count=0;}}}@Overridepublic void mousePressed(MouseEvent e) {// TODO Auto-generated method stubx1=e.getX();y1=e.getY();}@Overridepublic void mouseReleased(MouseEvent e) {// TODO Auto-generated method stubx2=e.getX();y2=e.getY();if(btnstr.equals(name[0])||btnstr.equals("")){g.drawLine(x1, y1, x2, y2);}else if(btnstr.equals(name[1])||btnstr.equals("")){g.drawRect(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x2-x1),Math.abs(y1-y2));}else if(btnstr.equals(name[2])||btnstr.equals("")){g.drawOval(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x2-x1),Math.abs(y1-y2));}}@Overridepublic void mouseEntered(MouseEvent e) {// TODO Auto-generated method stub}@Overridepublic void mouseExited(MouseEvent e) {// TODO Auto-generated method stub}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

java简单图形用户界面代码

java简单图形用户界面代码
}
}catch(FileNotFoundException e1){
e1.getStackTrace();
}catch(IOException e2){
e2.getStackTrace();
}
}
}
if(e.getSource()==registerBtn){
JFrame re=new Register();
centerPanel11=new JPanel();
centerPanel12=new JPanel();
//标题
titleLbl=new JLabel("欢迎进入考试系统");
titleLbl.setFont(new Font("隶书",Font.BOLD,24));
northPanel.add(titleLbl);
if (name.equals("")){
JOptionPane.showMessageDialog(null, "用户名不能为空,请重新输入用户名", "用户名空提示", JOptionPane.OK_OPTION);
userTxt.requestFocus();
return;
}
else if (pwd.equals("")){
//定义组件
JPanel northPanel,southPanel,centerPanel,centerPanel1,centerPanel11,centerPanel12;
JButton loginBtn,registerBtn,cancalBtn;
JLabel userLbl,passwordLbl,titleLbl;

Java基础之简单画图板的实现

Java基础之简单画图板的实现

Java基础之简单画图板的实现Java基础之简单画图板的实现不难理解,画图板就是主要用鼠标的各种操作实现在窗体界面上绘图。

所以实现一个简单的画图板,就必须先有一个事件源对象(窗体界面),为了更加美观,再在窗体界面上实例化两个面板对象,在其中一个面板对象上定义所画图形按钮(可以使用流式布局来世界面更美观);画图时,只在另一个面板对象上面进行操作。

代码如下:注:暂不考虑重绘问题如果想要在画图板面板上实现绘图,就必须为其添加一个监听器来监听鼠标对其的操作。

定义监听器的代码如下:这里我所写的简单画图板主要实现 "画笔","画直线","画矩形","画椭圆","画三角形","改变所画图形颜色","设置画笔粗细"的功能。

要实现画不同的图形,就必须要点击不同的按钮来选择要画的是一个什么样的图形,对此如果我们一个一个声明不同的按钮,则会定义较多的名称,而且还会影响代码的简洁性,所以可以将这些不同的按钮定义成一个数组中储存的对象,同理颜色按钮也可以声明一个数组来储存,在这里我选择字符串类数组储存按钮上的字符串,Color类数组储存按钮上的颜色。

实现代码如下:(注意添加监听器)最后,要实现画图,就必须获取画笔对象,获取画笔对象需要注意两点:1、图形画在哪个图形上,那么画笔组件就在这个图形上获取2、获取画笔对象,一定在窗体可见之后3、获取的画笔对象必须要用一个方法来传给自己定义的事件监听类中实现代码如下:其中DrawMouse类中定义了public void setG(Graphics g) {this.g = g;}方法来传递画笔。

以上的基本工作完成之后,就关注可以具体如何画出一个图形出来。

定义一个DrawMouse类继承了接口MouseListener, ActionListener,MouseMotionListener首先需要实例化一个Graphics对象g来接收传过来的画笔对象,由于我使用的是字符串数组来储存按钮上面的字符串,以及Color类的数组储存按钮的背景颜色,所以在重写ActionListener接口中的actionPerformed方法时,要首先获取按钮上的颜色或者文字,当获取的不是文字时,说明点击的是颜色按钮,读取按钮的颜色后给设置画笔的颜色;如果读取的是文字时,需要继续下一步的操作,实现代码如下:Java中提供了许多画图形的方法,画图的时候毫无疑问需要获取一定数量的坐标值,在继承的接口中的方法里,有一个MouseEvent 类型的形参e,可以通过调用getX(),getY()来获取经一定操作后当前位置的坐标的x值或y值。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

addMouseListener(this);
addMouseMotionListener(this);
JPanel mp=new JPanel();
mp.add(jb1);
mp.add(jb2);
mp.add(jb3);
this.add(jb1);
jb1.addActionListener(this);
this.add(jb2);
jb2.addActionListener(this);
this.add(jb3);
jb3.addActionListener(this);
g2d.draw(ellipse);
break;
case 3:
Rectangle2D rect(p1.getX(),p1.getY(),Math.abs(p1.getX()-p2.getX()),Math.abs(p1.getY()-p2.getY()));
break;
default:
}
}
}
}
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource()==jb1)
{
private int tool;
public int getTool() {
return tool;
}
public void setTool(int tool) {
this.tool = tool;
}
public int getX() {
return x;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
if(p1.getTool()==p2.getTool())
{
switch (p1.getTool())
{
case 0:
line=new Line2D.Double(p1.getX(),p1.getY(), p2.getX(), p2.getY());
import java.util.Vector;
import javax.swing.*;
public class PaintBoard
{
public static void main(String[] args)
{
new Panels();
}
}
class Point implements Serializable
g2d.draw(line);
break;
case 1:
line=new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY());
g2d.draw(line);
for(int i=0;i<paintVector.size()-1;i++)
{
p1=(Point)paintVector.elementAt(i);
p2=(Point)paintVector.elementAt(i+1);
g2d.setColor(p1.getColor());
this.add(jb4);
jb4.addActionListener(this);
this.add(jb5);
jb5.addActionListener(this);
this.add(jb6);
jb6.addActionListener(this);
Vector paintVector=new Vector();
FileDialog OpenPic,SavePic;
FileOutputStream Outpic;
FileInputStream Inpic;
ObjectInputStream In;
ObjectOutputStream Out;
this.setLocation(400, 200);
this.setVisible(true);
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mp.add(jb4);
mp.add(jb5);
mp.add(jb6);
mp.add(jb7);
mp.add(jb8);
mp.add(jb9);
this.add(mp,BorderLayout.NORTH);
this.setSize(650, 500);
{
this.x=a;
this.y=b;
this.color=color;
this.tool=t;
}
}
class Panels extends JFrame implements MouseListener,MouseMotionListener,ActionListener,ItemListener
this.add(jb7);
jb7.addActionListener(this);
jb8=new JButton("打开");
jb8.addActionListener(this);
jb9=new JButton("保存");
jb9.addActionListener(this);
return color;
}
public void setColor(Color color) {
this.color = color;
}
//设置工具选项
private int x,y;
private Color color;
public Point(int a,int b,Color c,int t)
{
painttool=0;
}
if(e.getSource()==jb2)
{
painttool=1;
}
if(e.getSource()==jb3)
{
painttool=2;
}
if(e.getSource()==jb4)
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Color getColor() {
jb2=new JButton("直线");
jb3=new JButton ("圆");
jb4=new JButton("矩形");
jb5=new JButton("橡皮");
jb6=new JButton("清除");
jb7=new JButton("调色板");
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public Panels()
{
OpenPic=new FileDialog(this, "打开图片", FileDialog.LOAD);
SavePic=new FileDialog(this,"保存图片", FileDialog.SAVE);
jb1=new JButton("画笔");
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
{
painttool=3;
}
if(e.getSource()==jb5)
{
painttool=4;
}
if(e.getSource()==jb6)
{
painttool=5;
paintVector.removeAllElements();
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.ByteOrder;
repaint();
}
if(e.getSource()==jb7)
相关文档
最新文档