From 1479eace7bcb838f50314d0925b568783496d175 Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:22:37 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20QAQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QAQ/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 QAQ/.keep diff --git a/QAQ/.keep b/QAQ/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From 261c15977dbbae3862195c7d8f25506cbd677e10 Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:26:17 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20QAQ=20?= =?UTF-8?q?=E4=B8=BA=20XYY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {QAQ => XYY}/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {QAQ => XYY}/.keep (100%) diff --git a/QAQ/.keep b/XYY/.keep similarity index 100% rename from QAQ/.keep rename to XYY/.keep -- Gitee From fdba62e6510b307af392fe7c0201102d343459b2 Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:26:40 +0800 Subject: [PATCH 3/9] add XYY/Draw. --- XYY/Draw | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 XYY/Draw diff --git a/XYY/Draw b/XYY/Draw new file mode 100644 index 0000000..92ede77 --- /dev/null +++ b/XYY/Draw @@ -0,0 +1,94 @@ +package java2020spring; + +import java.awt.BasicStroke; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import javax.swing.JFrame; +import java.awt.Color; +import java.awt.Dimension; +import javax.swing.JButton; + + +public class Draw extends JFrame{ + + public static void main(String[] args) { + Draw draw=new Draw(); + draw.Ondraw(); + } + private Paint[] array = new Paint[100000]; + private int x1, y1, x2, y2; + + public void paint (Graphics g) { + super.paint(g); + Graphics2D g2d = (Graphics2D) g; + + for (int i=0;i Date: Wed, 9 Jun 2021 22:27:22 +0800 Subject: [PATCH 4/9] add XYY/DrawListener. --- XYY/DrawListener | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 XYY/DrawListener diff --git a/XYY/DrawListener b/XYY/DrawListener new file mode 100644 index 0000000..c512cdd --- /dev/null +++ b/XYY/DrawListener @@ -0,0 +1,154 @@ +package java2020spring; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.Random; + +import javax.swing.JButton; +import javax.swing.JFrame; + +public class DrawListener implements MouseListener,MouseMotionListener,ActionListener{ + private int x1,x2,y1,y2; + private Graphics2D g; + public String name = "直线"; + private Color color = Color.red; + private JFrame frame; + + private Paint[] array; + private int index = 0; + + public DrawListener(JFrame frame,Paint[] array) { + this.frame = frame; + this.array = array; + } + + public void setG(Graphics g) { + this.g = (Graphics2D) g; + } + + public void actionPerformed(ActionEvent e) { + System.out.println("点击的按钮是:"+e.getActionCommand()); + if(e.getActionCommand().equals("")) { + JButton button = (JButton) e.getSource(); + color = button.getBackground(); + }else { + name=e.getActionCommand(); + } + } + + public void mouseDragged(MouseEvent e){ + x2 = e.getX(); + y2 = e.getY(); + switch(name) { + case "笔": + g.setStroke(new BasicStroke(2)); + g.drawLine(x1, y1, x2, y2); + Paint paint = new Paint(x1,y1,x2,y2,color,name,2); + if(index<1000) + array[index++] = paint; + x1 = x2; + y1 = y2; + break; + case "刷子": + g.setStroke(new BasicStroke(11)); + g.drawLine(x1, y1, x2, y2); + Paint pain = new Paint(x1,y1,x2,y2,color,name,11); + if(index<1000) + array[index++] = pain; + x1 = x2; + y1 = y2; + break; + case "橡皮": + color = frame.getContentPane().getBackground(); + g.setColor(color); + g.setStroke(new BasicStroke(50)); + g.drawLine(x1, y1, x2, y2); + Paint pai = new Paint(x1,y1,x2,y2,color,name,50); + if(index<1000) + array[index++] = pai; + x1 = x2; + y1 = y2; + break; + case "喷枪": + Random rand = new Random(); + for(int i=0;i<20;i++) + { + int p = rand.nextInt(20); + int q = rand.nextInt(20); + g.drawLine(x2+p, y2+q, x2+p, y2+q); + + Paint pa = new Paint(x2+p, y2+q, x2+p, y2+q,color,name); + if(index<1000) + array[index++] = pa; + } + x1 = x2; + y1 = y2; + break; + } + } + + public void mouseMoved(MouseEvent e) { + } + + public void mouseClicked(MouseEvent e) { + System.out.println("点击"); + } + + public void mousePressed(MouseEvent e) { + System.out.println("按下"); + x1 = e.getX(); + y1 = e.getY(); + g.setColor(color); + } + + public void mouseReleased(MouseEvent e) { + System.out.println("释放"); + x2 = e.getX(); + y2 = e.getY(); + + g.setStroke(new BasicStroke(1)); + switch(name) { + case "画直线": + g.drawLine(x1, y1, x2, y2); + Paint paint = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = paint; + break; + + case "画矩形": + g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2),Math.abs(y1-y2)); + Paint k = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = k; + break; + + case "画圆": + g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2),Math.abs(y1-y2)); + Paint f = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = f; + break; + + case "点我": + g.drawString("老师幸苦了谢谢老师~", x1, y1); + Paint j = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = j; + break; + } + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } +} \ No newline at end of file -- Gitee From 17739694945d4d8a70913ef45cce9d27b984668b Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:27:47 +0800 Subject: [PATCH 5/9] add XYY/paint. --- XYY/paint | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 XYY/paint diff --git a/XYY/paint b/XYY/paint new file mode 100644 index 0000000..1831e52 --- /dev/null +++ b/XYY/paint @@ -0,0 +1,74 @@ +package java2020spring; + +import java.awt.Color; + +public class Paint { + private int x1,y1,x2,y2; + private Color color; + private String name; + private int width; + + public Paint(int x1, int y1, int x2, int y2, Color color, String name) { + super(); + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.name = name; + } + + public Paint(int x1, int y1, int x2, int y2, Color color, String name, int width) { + super(); + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.name = name; + this.width = width; + } + + public int getX1() { + return x1; + } + public void setX1(int x1) { + this.x1 = x1; + } + public int getY1() { + return y1; + } + public void setY1(int y1) { + this.y1 = y1; + } + public int getX2() { + return x2; + } + public void setX2(int x2) { + this.x2 = x2; + } + public int getY2() { + return y2; + } + public void setY2(int y2) { + this.y2 = y2; + } + public Color getColor() { + return color; + } + public void setColor(Color color) { + this.color = color; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public int getWidth() { + return width; + } + public void setWidth(int width) { + this.width = width; + } +} \ No newline at end of file -- Gitee From 15947aa1b802cf2a24091c89d886aad9934a8d2f Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:37:09 +0800 Subject: [PATCH 6/9] add src/java2020spring/Draw. --- src/java2020spring/Draw | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/java2020spring/Draw diff --git a/src/java2020spring/Draw b/src/java2020spring/Draw new file mode 100644 index 0000000..92ede77 --- /dev/null +++ b/src/java2020spring/Draw @@ -0,0 +1,94 @@ +package java2020spring; + +import java.awt.BasicStroke; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import javax.swing.JFrame; +import java.awt.Color; +import java.awt.Dimension; +import javax.swing.JButton; + + +public class Draw extends JFrame{ + + public static void main(String[] args) { + Draw draw=new Draw(); + draw.Ondraw(); + } + private Paint[] array = new Paint[100000]; + private int x1, y1, x2, y2; + + public void paint (Graphics g) { + super.paint(g); + Graphics2D g2d = (Graphics2D) g; + + for (int i=0;i Date: Wed, 9 Jun 2021 22:37:44 +0800 Subject: [PATCH 7/9] add src/java2020spring/DrawListener. --- src/java2020spring/DrawListener | 154 ++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/java2020spring/DrawListener diff --git a/src/java2020spring/DrawListener b/src/java2020spring/DrawListener new file mode 100644 index 0000000..c512cdd --- /dev/null +++ b/src/java2020spring/DrawListener @@ -0,0 +1,154 @@ +package java2020spring; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.Random; + +import javax.swing.JButton; +import javax.swing.JFrame; + +public class DrawListener implements MouseListener,MouseMotionListener,ActionListener{ + private int x1,x2,y1,y2; + private Graphics2D g; + public String name = "直线"; + private Color color = Color.red; + private JFrame frame; + + private Paint[] array; + private int index = 0; + + public DrawListener(JFrame frame,Paint[] array) { + this.frame = frame; + this.array = array; + } + + public void setG(Graphics g) { + this.g = (Graphics2D) g; + } + + public void actionPerformed(ActionEvent e) { + System.out.println("点击的按钮是:"+e.getActionCommand()); + if(e.getActionCommand().equals("")) { + JButton button = (JButton) e.getSource(); + color = button.getBackground(); + }else { + name=e.getActionCommand(); + } + } + + public void mouseDragged(MouseEvent e){ + x2 = e.getX(); + y2 = e.getY(); + switch(name) { + case "笔": + g.setStroke(new BasicStroke(2)); + g.drawLine(x1, y1, x2, y2); + Paint paint = new Paint(x1,y1,x2,y2,color,name,2); + if(index<1000) + array[index++] = paint; + x1 = x2; + y1 = y2; + break; + case "刷子": + g.setStroke(new BasicStroke(11)); + g.drawLine(x1, y1, x2, y2); + Paint pain = new Paint(x1,y1,x2,y2,color,name,11); + if(index<1000) + array[index++] = pain; + x1 = x2; + y1 = y2; + break; + case "橡皮": + color = frame.getContentPane().getBackground(); + g.setColor(color); + g.setStroke(new BasicStroke(50)); + g.drawLine(x1, y1, x2, y2); + Paint pai = new Paint(x1,y1,x2,y2,color,name,50); + if(index<1000) + array[index++] = pai; + x1 = x2; + y1 = y2; + break; + case "喷枪": + Random rand = new Random(); + for(int i=0;i<20;i++) + { + int p = rand.nextInt(20); + int q = rand.nextInt(20); + g.drawLine(x2+p, y2+q, x2+p, y2+q); + + Paint pa = new Paint(x2+p, y2+q, x2+p, y2+q,color,name); + if(index<1000) + array[index++] = pa; + } + x1 = x2; + y1 = y2; + break; + } + } + + public void mouseMoved(MouseEvent e) { + } + + public void mouseClicked(MouseEvent e) { + System.out.println("点击"); + } + + public void mousePressed(MouseEvent e) { + System.out.println("按下"); + x1 = e.getX(); + y1 = e.getY(); + g.setColor(color); + } + + public void mouseReleased(MouseEvent e) { + System.out.println("释放"); + x2 = e.getX(); + y2 = e.getY(); + + g.setStroke(new BasicStroke(1)); + switch(name) { + case "画直线": + g.drawLine(x1, y1, x2, y2); + Paint paint = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = paint; + break; + + case "画矩形": + g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2),Math.abs(y1-y2)); + Paint k = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = k; + break; + + case "画圆": + g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2),Math.abs(y1-y2)); + Paint f = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = f; + break; + + case "点我": + g.drawString("老师幸苦了谢谢老师~", x1, y1); + Paint j = new Paint(x1,y1,x2,y2,color,name,1); + if(index<1000) + array[index++] = j; + break; + } + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } +} \ No newline at end of file -- Gitee From 67cf95d172e3cc4f74d3362ececb6b572242efc0 Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:38:06 +0800 Subject: [PATCH 8/9] add src/java2020spring/paint. --- src/java2020spring/paint | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/java2020spring/paint diff --git a/src/java2020spring/paint b/src/java2020spring/paint new file mode 100644 index 0000000..1831e52 --- /dev/null +++ b/src/java2020spring/paint @@ -0,0 +1,74 @@ +package java2020spring; + +import java.awt.Color; + +public class Paint { + private int x1,y1,x2,y2; + private Color color; + private String name; + private int width; + + public Paint(int x1, int y1, int x2, int y2, Color color, String name) { + super(); + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.name = name; + } + + public Paint(int x1, int y1, int x2, int y2, Color color, String name, int width) { + super(); + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.name = name; + this.width = width; + } + + public int getX1() { + return x1; + } + public void setX1(int x1) { + this.x1 = x1; + } + public int getY1() { + return y1; + } + public void setY1(int y1) { + this.y1 = y1; + } + public int getX2() { + return x2; + } + public void setX2(int x2) { + this.x2 = x2; + } + public int getY2() { + return y2; + } + public void setY2(int y2) { + this.y2 = y2; + } + public Color getColor() { + return color; + } + public void setColor(Color color) { + this.color = color; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public int getWidth() { + return width; + } + public void setWidth(int width) { + this.width = width; + } +} \ No newline at end of file -- Gitee From 143954f230a7974257f860240b9deb080aaaa3f9 Mon Sep 17 00:00:00 2001 From: QAQ_0322_xiaoyiyan <1070584156@qq.com> Date: Wed, 9 Jun 2021 22:38:16 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20XYY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XYY/.keep | 0 XYY/Draw | 94 ----------------------------- XYY/DrawListener | 154 ----------------------------------------------- XYY/paint | 74 ----------------------- 4 files changed, 322 deletions(-) delete mode 100644 XYY/.keep delete mode 100644 XYY/Draw delete mode 100644 XYY/DrawListener delete mode 100644 XYY/paint diff --git a/XYY/.keep b/XYY/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/XYY/Draw b/XYY/Draw deleted file mode 100644 index 92ede77..0000000 --- a/XYY/Draw +++ /dev/null @@ -1,94 +0,0 @@ -package java2020spring; - -import java.awt.BasicStroke; -import java.awt.FlowLayout; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import javax.swing.JFrame; -import java.awt.Color; -import java.awt.Dimension; -import javax.swing.JButton; - - -public class Draw extends JFrame{ - - public static void main(String[] args) { - Draw draw=new Draw(); - draw.Ondraw(); - } - private Paint[] array = new Paint[100000]; - private int x1, y1, x2, y2; - - public void paint (Graphics g) { - super.paint(g); - Graphics2D g2d = (Graphics2D) g; - - for (int i=0;i