Advertisement
TrodelHD

Untitled

Apr 2nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.BasicStroke;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.awt.RenderingHints;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseMotionAdapter;
  12. import java.util.ArrayList;
  13.  
  14. import javax.swing.JComponent;
  15.  
  16.  
  17. public class DrawAreaRater extends JComponent {
  18.  
  19. public Connection con;
  20.  
  21. public int radius;
  22. // Image in which we're going to draw
  23. private Image image;
  24. // Graphics2D object ==> used to draw on
  25. public Graphics2D g2;
  26. // Mouse coordinates
  27.  
  28. public DrawAreaRater() {
  29. setDoubleBuffered(false);
  30.  
  31. }
  32. public void drawLine(int radius, int oldX, int oldY, int currentX, int currentY,int r ,int g, int b){
  33. g2.setColor(new Color(r, g, b));
  34. g2.setStroke(new BasicStroke(radius, 1, 1));
  35. g2.drawLine(oldX, oldY, currentX, currentY);
  36. g2.setStroke(new BasicStroke(radius));
  37. repaint();
  38. }
  39.  
  40. protected void paintComponent(Graphics g) {
  41. if (image == null) {
  42. // image to draw null ==> we create
  43. image = createImage(900, 830);
  44. g2 = (Graphics2D) image.getGraphics();
  45. // enable antialiasing
  46. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  47. // clear draw area
  48. clear();
  49. }
  50.  
  51. g.drawImage(image, 20, 20, null);
  52. }
  53.  
  54. // now we create exposed methods
  55. public void clear() {
  56. g2.setPaint(Color.white);
  57. // draw white on entire draw area to clear
  58. g2.fillRect(-20, -20, getSize().width, getSize().height);
  59. g2.setPaint(Color.black);
  60. repaint();
  61. }
  62.  
  63. public void setColor(Color c) {
  64. // apply red color on g2 context
  65. g2.setPaint(c);
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement