Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jensenpj;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.geom.Point2D;
- import java.util.ArrayList;
- import java.util.List;
- import javax.swing.*;
- public class Main {
- public static void main(String[] args) {
- List<Point2D> points = new ArrayList<Point2D>();
- points = hardCode(points);
- // QuickHull quickHull = new QuickHull(points);
- JFrame p = new JFrame();
- JPanel controls = new JPanel();
- PaintingPanel pointPainter = new PaintingPanel();
- controls.setLayout(null);
- p.setContentPane(controls);
- JLabel numPoints1 = new JLabel("Enter the # of points");
- JLabel numPoints = new JLabel("as a positive integer:");
- JLabel sortOptions = new JLabel("Choose the sort method:");
- final JTextArea inputText = new JTextArea("2");
- JButton genPoints = new JButton("Generate Points");
- ButtonGroup radioButtons = new ButtonGroup();
- JRadioButton quickHull = new JRadioButton("Quick Hull");
- JRadioButton mergeHull = new JRadioButton("Merge Hull");
- radioButtons.add(quickHull);
- radioButtons.add(mergeHull);
- JButton genHull = new JButton("Generate Hull");
- p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- p.setSize(650, 482);
- p.setLayout(null);
- p.setLocation(425,150);
- p.setTitle("Convex Hull Finder");
- //add all the pieces to the frame
- controls.add(genHull);
- controls.add(quickHull);
- controls.add(mergeHull);
- controls.add(numPoints);
- controls.add(inputText);
- controls.add(genPoints);
- controls.add(numPoints1);
- controls.add(sortOptions);
- //
- //place the pieces
- genHull.setBounds(5,300,150,40);
- quickHull.setBounds(30,250,100,20);
- mergeHull.setBounds(30,275,100,20);
- genPoints.setBounds(5,100,150,30);
- inputText.setBounds(30, 70, 90, 20);
- numPoints1.setBounds(18, 30, 120, 25);
- numPoints.setBounds(18, 45, 120, 25);
- sortOptions.setBounds(10,220,150,30);
- p.setVisible(true);
- genPoints.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int numberOfPoints = Integer.parseInt(inputText.getText());
- System.out.println("Number of Points: " + numberOfPoints);
- for(int i = 0; i < numberOfPoints; i++){
- int randX = (int)(425 * Math.random());
- int randY = (int)(425 * Math.random());
- Point2D point = new Point2D.Double(randX,randY);
- pointPainter.add(point);
- }
- //
- // String val = tf.getText();
- // l.setText(val);
- }
- });
- p.add(pointPainter);
- pointPainter.setBounds(200, 10,425, 425);
- // pointPainter.setBackground(Color.BLUE);
- }
- private static List<Point2D> hardCode(List<Point2D> points) {
- //[(6, 7), (16, 4), (10, 12), (2, 14), (14, 2), (12, 10), (4, 16), (7, 6)]
- Point2D point1 = new Point2D.Double(); //Point2D.Double();
- Point2D point2 = new Point2D.Double();
- Point2D point3 = new Point2D.Double();
- Point2D point4 = new Point2D.Double();
- Point2D point5 = new Point2D.Double();
- Point2D point6 = new Point2D.Double();
- Point2D point7 = new Point2D.Double();
- Point2D point8 = new Point2D.Double();
- Point2D point9 = new Point2D.Double();
- Point2D point10 = new Point2D.Double();
- point1.setLocation(6, 7);
- point2.setLocation(16, 4);
- point3.setLocation(10, 12);
- point4.setLocation(2, 14);
- point5.setLocation(-14, 2);
- point6.setLocation(12, 10);
- point7.setLocation(4, -16);
- point8.setLocation(7, 6);
- point9.setLocation(-7, 6);
- point10.setLocation(7, -6);
- points.add(point1);
- points.add(point2);
- points.add(point3);
- points.add(point4);
- points.add(point5);
- points.add(point6);
- points.add(point7);
- points.add(point8);
- points.add(point9);
- points.add(point10);
- return points;
- }
- }
- package jensenpj;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.geom.Point2D;
- import java.util.ArrayList;
- import javax.swing.JPanel;
- public class PaintingPanel extends JPanel {
- protected ArrayList<Point2D> drawlist = new ArrayList<Point2D>();
- protected Point2D temp;
- public PaintingPanel() {
- setBackground(Color.darkGray);
- }
- public void addPoint(Point2D p) {
- drawlist.add(p);
- }
- public void printTemp(Point2D p) {
- temp = p;
- repaint();
- }
- // public void paintComponent(Graphics g) {
- // super.paintComponent(g);
- // if (temp != null) {
- // temp.draw(g);
- // }
- // for (Point2D obj : drawlist) {
- // obj.draw(g);
- // }
- //
- // }
- public void clearTemp(){
- temp = null;
- }
- public void add(Point2D point) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement