Guest User

DrawLine.java

a guest
Jun 8th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package utils;
  2.  
  3. import java.awt.BasicStroke;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.geom.Line2D;
  7.  
  8. import javax.swing.JComponent;
  9.  
  10. public class DrawLine extends JComponent {
  11.     private int x1;
  12.     private int x2;
  13.     private int y1;
  14.     private int y2;
  15.     private int width;
  16.  
  17.     public DrawLine(int x1, int y1, int x2, int y2, int width) {
  18.         this.x1 = x1;
  19.         this.y1 = y1;
  20.         this.x2 = x2;
  21.         this.y2 = y2;
  22.         this.width = width;
  23.     }
  24.  
  25.     @Override
  26.     protected void paintComponent(Graphics graphics) {
  27.         super.paintComponent(graphics);
  28.  
  29.         Graphics2D graphics2d = (Graphics2D) graphics;
  30.         graphics2d.setStroke(new BasicStroke(this.width));
  31.         graphics2d.draw(new Line2D.Float(this.x1, this.y1, this.x2, this.y2));
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment