Write a program that passes the coordinates of five points


Write a program that passes the coordinates of five points from the command line as follows java Exercise13_31 x1 y1 x2 y2 x3 y3 x4 y4 x5 y5. The first four points for a polygon, and the program displays the polygon in a panel and a message in a alabel that indicates wheter the fifth point is inside the polygon.

Here is what i have so far...

import javax.swing.*;

import java.awt.*;

public class Lab13_31Montgomery extends JFrame {

private JLabel jlblMessage = new JLabel("", JLabel.CENTER);

public Lab13_31Montgomery() {

setTitle("Draw Polygon");

add(new PolygonPanel());

add(jlblMessage, BorderLayout.SOUTH);

if (polygon.contains(p1))

jlblMessage.setText("The point is inside the polygon");

else

jlblMessage.setText("The point is outside the polygon");

}

 

}

 

public static void main(String[] args) {

//prompt user to enter points

System.out.println("Enter 5 points, first four are points of Polygon, the last is to be tested");

 

// Pass command-line arguments

if (args.length != 10) {

System.out.println(

"Usage: java Exercise14_32 x1 y1 x2 y2 x3 y3 x4 y4 x5 y5");

System.exit(1);

}

Lab13_31Montgomery frame = new Lab13_31Montgomery();

frame.setSize(400, 400);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

Polygon polygon = new Polygon();

polygon.addPoint(Integer.parseInt(args[0]), Integer.parseInt(args[1]));

polygon.addPoint(Integer.parseInt(args[2]), Integer.parseInt(args[3]));

polygon.addPoint(Integer.parseInt(args[4]), Integer.parseInt(args[5]));

polygon.addPoint(Integer.parseInt(args[6]), Integer.parseInt(args[7]));

}

}

class PolygonPanel extends JPanel {

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

g.drawPolygon(polygon);

}

}

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a program that passes the coordinates of five points
Reference No:- TGS0661365

Expected delivery within 24 Hours