Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import java.awt.BasicStroke;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.geom.Line2D;
- import javax.swing.JComponent;
- public class DrawLine extends JComponent {
- private int x1;
- private int x2;
- private int y1;
- private int y2;
- private int width;
- public DrawLine(int x1, int y1, int x2, int y2, int width) {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.width = width;
- }
- @Override
- protected void paintComponent(Graphics graphics) {
- super.paintComponent(graphics);
- Graphics2D graphics2d = (Graphics2D) graphics;
- graphics2d.setStroke(new BasicStroke(this.width));
- graphics2d.draw(new Line2D.Float(this.x1, this.y1, this.x2, this.y2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment