Advertisement
Guest User

Untitled

a guest
May 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import java.util.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6.  
  7.  
  8. public class AlexanderWU3A1Q1 {
  9.  
  10. public static void main(String[] args) { // main method
  11. JFrame frame = new JFrame(); // makes new frame object
  12. frame.setTitle("Drawing Tool"); // sets title
  13. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes application when exit button clicked
  14. frame.setPreferredSize(new Dimension(840, 840)); // sets dimensions for frame
  15. frame.setResizable(false); // not resizable
  16.  
  17. JPanel panel = new JPanel();
  18.  
  19. frame.pack();
  20. frame.setVisible(true); // sets frame visible
  21.  
  22. ArrayList<ArrayList<String> > array = new ArrayList<>();
  23. try (Scanner scanner = new Scanner(new File("eng-climate-summaries-All-4,2018.csv"));) {
  24. while (scanner.hasNext()) {
  25. array.add(parseThings(scanner.nextLine()));
  26. }
  27. } catch (Exception FileNotFoundException) {
  28. }
  29.  
  30. ArrayList<String> stationNames = new ArrayList<>();
  31. Vector<String> stationNamesArray = new Vector<>(stationNames);
  32. for (int i = 32; i < 1114; i++) {
  33. String e = array.get(i).get(0);
  34. stationNames.add(e);
  35. }
  36.  
  37. JComboBox chooseLocation = new JComboBox(stationNamesArray);
  38. chooseLocation.setEditable(false);
  39.  
  40. panel.add(chooseLocation);
  41. frame.add(panel); // add JPanel to frame
  42.  
  43. }
  44.  
  45. private static ArrayList<String> parseThings(String Line) {
  46. ArrayList<String> lines = new ArrayList<>();
  47. try (Scanner scanRows = new Scanner(Line)) {
  48. scanRows.useDelimiter(",");
  49. while (scanRows.hasNext()) {
  50. String temp = scanRows.next();
  51. try {
  52. temp = temp.substring(1, temp.length() - 1);
  53. lines.add(temp);
  54. } catch (Exception e) {}
  55. }
  56. }
  57. return lines;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement