Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.63 KB | None | 0 0
  1. package jensenpj;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.FlowLayout;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.geom.Point2D;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import javax.swing.*;
  13.  
  14. public class Main {
  15.  
  16.     public static void main(String[] args) {
  17.         List<Point2D> points = new ArrayList<Point2D>();
  18.         points = hardCode(points);
  19. //      QuickHull quickHull = new QuickHull(points);
  20.  
  21.         JFrame p = new JFrame();
  22.         JPanel controls = new JPanel();
  23.         PaintingPanel pointPainter = new PaintingPanel();
  24.        
  25.         controls.setLayout(null);
  26.         p.setContentPane(controls);
  27.         JLabel numPoints1 = new JLabel("Enter the # of points");
  28.         JLabel numPoints = new JLabel("as a positive integer:");
  29.         JLabel sortOptions = new JLabel("Choose the sort method:");
  30.         final JTextArea inputText = new JTextArea("2");
  31.         JButton genPoints = new JButton("Generate Points");
  32.         ButtonGroup radioButtons = new ButtonGroup();
  33.         JRadioButton quickHull = new JRadioButton("Quick Hull");
  34.         JRadioButton mergeHull = new JRadioButton("Merge Hull");
  35.         radioButtons.add(quickHull);
  36.         radioButtons.add(mergeHull);
  37.         JButton genHull = new JButton("Generate Hull");
  38.         p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39.         p.setSize(650, 482);
  40.         p.setLayout(null);
  41.         p.setLocation(425,150);
  42.         p.setTitle("Convex Hull Finder");
  43.             //add all the pieces to the frame
  44.         controls.add(genHull);
  45.         controls.add(quickHull);
  46.         controls.add(mergeHull);
  47.         controls.add(numPoints);
  48.         controls.add(inputText);
  49.         controls.add(genPoints);
  50.         controls.add(numPoints1);
  51.         controls.add(sortOptions);
  52.         //
  53.        
  54.        
  55.         //place the pieces
  56.         genHull.setBounds(5,300,150,40);
  57.         quickHull.setBounds(30,250,100,20);
  58.         mergeHull.setBounds(30,275,100,20);
  59.         genPoints.setBounds(5,100,150,30);
  60.         inputText.setBounds(30, 70, 90, 20);
  61.         numPoints1.setBounds(18, 30, 120, 25);
  62.         numPoints.setBounds(18, 45, 120, 25);
  63.         sortOptions.setBounds(10,220,150,30);
  64.         p.setVisible(true);
  65.        
  66.         genPoints.addActionListener(new ActionListener() {
  67.             public void actionPerformed(ActionEvent e) {
  68.                 int numberOfPoints = Integer.parseInt(inputText.getText());
  69.                 System.out.println("Number of Points: " + numberOfPoints);
  70.                 for(int i = 0; i < numberOfPoints; i++){
  71.                     int randX = (int)(425 *  Math.random());
  72.                     int randY = (int)(425 *  Math.random());
  73.                     Point2D point = new Point2D.Double(randX,randY);
  74.                     pointPainter.add(point);
  75.                 }
  76. //             
  77. //              String val =  tf.getText();
  78. //              l.setText(val);
  79.             }
  80.            
  81.         });
  82.         p.add(pointPainter);
  83.         pointPainter.setBounds(200, 10,425, 425);
  84.     //  pointPainter.setBackground(Color.BLUE);
  85.        
  86.        
  87.     }
  88.  
  89.     private static List<Point2D> hardCode(List<Point2D> points) {
  90.         //[(6, 7), (16, 4), (10, 12), (2, 14), (14, 2), (12, 10), (4, 16), (7, 6)]
  91.         Point2D point1 = new Point2D.Double(); //Point2D.Double();
  92.         Point2D point2 = new Point2D.Double();
  93.         Point2D point3 = new Point2D.Double();
  94.         Point2D point4 = new Point2D.Double();
  95.         Point2D point5 = new Point2D.Double();
  96.         Point2D point6 = new Point2D.Double();
  97.         Point2D point7 = new Point2D.Double();
  98.         Point2D point8 = new Point2D.Double();
  99.         Point2D point9 = new Point2D.Double();
  100.         Point2D point10 = new Point2D.Double();
  101.         point1.setLocation(6, 7);
  102.         point2.setLocation(16, 4);
  103.         point3.setLocation(10, 12);
  104.         point4.setLocation(2, 14);
  105.         point5.setLocation(-14, 2);
  106.         point6.setLocation(12, 10);
  107.         point7.setLocation(4, -16);
  108.         point8.setLocation(7, 6);
  109.         point9.setLocation(-7, 6);
  110.         point10.setLocation(7, -6);
  111.         points.add(point1);
  112.         points.add(point2);
  113.         points.add(point3);
  114.         points.add(point4);
  115.         points.add(point5);
  116.         points.add(point6);
  117.         points.add(point7);
  118.         points.add(point8);
  119.         points.add(point9);
  120.         points.add(point10);
  121.         return points;
  122.     }
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. package jensenpj;
  132.  
  133.  
  134. import java.awt.Color;
  135. import java.awt.Graphics;
  136. import java.awt.geom.Point2D;
  137. import java.util.ArrayList;
  138. import javax.swing.JPanel;
  139.  
  140. public class PaintingPanel extends JPanel {
  141.     protected ArrayList<Point2D> drawlist = new ArrayList<Point2D>();
  142.     protected Point2D temp;
  143.  
  144.     public PaintingPanel() {
  145.         setBackground(Color.darkGray);
  146.     }
  147.  
  148.     public void addPoint(Point2D p) {
  149.         drawlist.add(p);
  150.     }
  151.  
  152.     public void printTemp(Point2D p) {
  153.         temp = p;
  154.         repaint();
  155.     }
  156.  
  157. //  public void paintComponent(Graphics g) {
  158. //      super.paintComponent(g);
  159. //      if (temp != null) {
  160. //          temp.draw(g);
  161. //      }
  162. //      for (Point2D obj : drawlist) {
  163. //          obj.draw(g);
  164. //      }
  165. //
  166. //  }
  167.     public void clearTemp(){
  168.         temp = null;
  169.     }
  170.  
  171.     public void add(Point2D point) {
  172.         // TODO Auto-generated method stub
  173.        
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement