Пример #1
0
  /**
   * Description of loadDate()) Constructs a person bean from each line of text from the input file
   * and adds it to an observable list.
   */
  private void loadData() {
    try {
      // System.out.println(Paths.get("mydata.txt").toAbsolutePath());
      // List<String> lines = Files.readAllLines(Paths.get("build/resource/mydata.txt"),
      // Charset.defaultCharset());
      BufferedReader br = new BufferedReader(new FileReader("build/resource/mydata.txt"));
      String line;
      String data[] = new String[4];

      while (true) {
        line = br.readLine();
        if (line == null) {
          break;
        } else {
          data = line.split(",");
          System.out.println(data);
          PersonBean p = new PersonBean(data[0], data[1], data[2], new Integer(data[3]));
          personData.add(p);
        }
      } // *****End for
      br.close();
      System.out.println("Loaded " + data.length + " rows of data.");
    } catch (Exception e) {
      System.out.println("There was a problem loading the file:" + e.getMessage());
      e.printStackTrace();
    }
  }
  private void initPane() {
    //		WebEngine engine = optionView.getEngine();
    try {
      Document document = Jsoup.connect(webView.getEngine().getLocation()).get();
      Element table =
          document.select("#normal_basket_" + document.select("[name=item_id]").val()).first();
      Element td = table.select("td").first();
      Elements spans = td.select("span");
      Elements selects = td.select("select");
      //			System.out.println(spans.size());
      cmb = new ArrayList<ComboBox>();
      for (int i = 0; i < spans.size(); i++) {

        ObservableList<ValuePair> obs = FXCollections.observableArrayList();
        Elements options = selects.get(i).select("option");
        for (int k = 0; k < options.size(); k++) {
          Element option = options.get(k);
          obs.add(new ValuePair("choice", option.text(), option.val()));
        }

        cmb.add(new ComboBox<ValuePair>(obs));
        optionArea.getChildren().addAll(new Text(spans.get(i).text()), cmb.get(i));
      }

    } catch (Exception e) {
      // TODO 自動生成された catch ブロック
      e.printStackTrace();
    }
  }
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    // TODO 自動生成されたメソッド・スタブ
    addOption.setOnAction(
        event -> {
          for (int i = 0; i < cmb.size(); i++) {
            //				System.out.println(cmb.get(i).getValue());
            if (cmb.get(i).getValue() == null) {
              break;
            } else if (i == cmb.size() - 1) {
              addTask.setDisable(false);
            }
          }
        });

    addTask.setOnAction(
        event -> {
          try {
            String url = webView.getEngine().getLocation();
            System.out.println(url);
            Document document = Jsoup.connect(url).get();

            Elements input = document.select("input");

            Map params = new HashMap<String, String>();
            for (ComboBox cmbx : cmb) {
              ValuePair vp = (ValuePair) cmbx.getValue();
              params.put(vp.getName(), vp.getvalue());
            }
            //				System.out.println(input.select("[name=shop_bid]").first());
            //				System.out.println(input.select("[name=shop_bid]").first().val());
            params.put("shop_bid", input.select("[name=shop_bid]").first().val());
            params.put("item_id", input.select("[name=item_id]").first().val());
            params.put("__event", input.select("[name=__event]").first().val());
            params.put("units", "1");

            Map map = new HashMap<String, Long>();

            //				System.out.println(document.select("#stime").size());
            if (document.select("#stime").size() != 0) {
              System.out.println(document.select("#stime"));
              map.put("stime", Long.parseLong((input.select("#stime").first().val())));
              map.put("etime", Long.parseLong((input.select("#etime").first().val())));
            } else {
              map = null;
            }

            BuyTask task = new BuyTask(url, params, map);
            task.call();
            this.getScene().getWindow().hide();
          } catch (Exception e) {
            // TODO 自動生成された catch ブロック
            e.printStackTrace();
          }
        });
  }
Пример #4
0
 public void traceLM(OneFrame frame) {
   setCoor(frame);
   updateGraphic();
   try {
     Thread.currentThread().sleep(40);
   } catch (InterruptedException e) {
     try {
       Thread.currentThread().join();
     } catch (Exception f) {
       f.printStackTrace();
     }
     e.printStackTrace();
     e.printStackTrace();
   }
 }
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    urlField.setOnAction(
        event -> {
          String text = urlField.getText();
          urlField.setText("tetetetetetetete");
          webView.getEngine().load(text);
        });

    webView
        .getEngine()
        .getLoadWorker()
        .stateProperty()
        .addListener(
            (ov, oldState, newState) -> {
              if (newState == State.SUCCEEDED) {
                String url = webView.getEngine().getLocation();
                urlField.setText(url);
                if (Pattern.compile("http://item.rakuten.co.jp/.*").matcher(url).find()) {
                  try {
                    Elements tmp;
                    Document document = Jsoup.connect(url).get();
                    tmp = document.select("input");
                    tmp = tmp.select("#etime");
                    if (tmp.size() != 0) {
                      if (!(Long.parseLong(tmp.first().val()) < new Date().getTime())) {
                        entryButton.setDisable(false);
                      }
                    } else {
                      entryButton.setDisable(false);
                    }
                  } catch (Exception e) {
                    // TODO 自動生成された catch ブロック
                    e.printStackTrace();
                  }
                }
              }
              ;
            });

    entryButton.setOnAction(
        event -> {
          urlField.setText("webView disable");
          sendEntryTaskController();
        });
  }
Пример #6
0
  /** Writes the data to file. */
  private void writeIt() {
    try {
      //			FileWriter writer = new FileWriter("build/resource/mydata.txt");
      BufferedWriter writer = new BufferedWriter(new FileWriter("build/resource/mydata.txt"));

      Iterator<PersonBean> it = personData.iterator();
      while (it.hasNext()) {
        String x;
        PersonBean p = it.next();
        writer.write(
            p.getFirstAndLastName() + "," + p.getEmail() + "," + p.getGender() + "," + p.getAge());

        if (it.hasNext()) {
          writer.newLine();
        }
        System.out.println("First and last: " + p.getFirstAndLastName());
      }
      writer.close();
    } catch (Exception e) {
      System.out.println("There was a problem saving the file:" + e.getMessage());
    }
  }