Skip to content

Instantly share code, notes, and snippets.

@MinSomai
Created February 22, 2020 17:47
Show Gist options
  • Save MinSomai/3b6de879c70d90fd60a7a932d732bf65 to your computer and use it in GitHub Desktop.
Save MinSomai/3b6de879c70d90fd60a7a932d732bf65 to your computer and use it in GitHub Desktop.
Lines in Java 2D
package hw;
import java.awt.*;
import javax.swing.*;
import java.util.Scanner;
public class LineJava2D13 extends JPanel {
public static int x1,x2,y1,y2;
public void paintComponent(Graphics g) {
g.drawLine(x1, y1, x2, y2);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Coordinates for Line (4): ");
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
JFrame frame=new JFrame();
frame.setSize(500, 500);
frame.setVisible(true);
frame.setTitle("Line Example in Java 2D.");
frame.setContentPane(new LineJava2D13());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment