コード例 #1
0
ファイル: test.java プロジェクト: taepeep/AccountingNote
 public String setPickedDate() {
   if (day.equals("")) return day;
   java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
   java.util.Calendar cal = java.util.Calendar.getInstance();
   cal.set(year, month, Integer.parseInt(day));
   return sdf.format(cal.getTime());
 }
コード例 #2
0
    // Creates a new thread, runs the program in that thread, and reports any errors as needed.
    private void run(String clazz) {
      try {
        // Makes sure the JVM resets if it's already running.
        if (JVMrunning) kill();

        // Some String constants for java path and OS-specific separators.
        String separator = System.getProperty("file.separator");
        String path = System.getProperty("java.home") + separator + "bin" + separator + "java";

        // Tries to run compiled code.
        ProcessBuilder builder = new ProcessBuilder(path, clazz);

        // Should be good now! Everything past this is on you. Don't mess it up.
        println(
            "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
        println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr);

        JVM = builder.start();

        // Note that as of right now, there is no support for input. Only output.
        Reader errorReader = new InputStreamReader(JVM.getErrorStream());
        Reader outReader = new InputStreamReader(JVM.getInputStream());
        // Writer inReader = new OutputStreamWriter(JVM.getOutputStream());

        redirectErr = redirectIOStream(errorReader, err);
        redirectOut = redirectIOStream(outReader, out);
        // redirectIn = redirectIOStream(null, inReader);
      } catch (Exception e) {
        // This catches any other errors we might get.
        println("Some error thrown", progErr);
        logError(e.toString());
        displayLog();
        return;
      }
    }
コード例 #3
0
ファイル: test.java プロジェクト: taepeep/AccountingNote
 public void displayDate() {
   for (int x = 7; x < button.length; x++) button[x].setText("");
   java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM yyyy");
   java.util.Calendar cal = java.util.Calendar.getInstance();
   cal.set(year, month, 1);
   int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
   int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
   for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++)
     button[x].setText("" + day);
   l.setText(sdf.format(cal.getTime()));
   d.setTitle("Date Picker");
 }
コード例 #4
0
    // Kills the JVM process and any active threads on it.
    private void kill() {
      if (redirectErr != null) {
        redirectErr.close();
        redirectErr.interrupt();
      }

      if (redirectOut != null) {
        redirectOut.close();
        redirectOut.interrupt();
      }

      if (JVM != null) {
        JVM.destroy();
        JVM = null;
      }

      JVMrunning = false;

      println("JVM reset on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
    }
コード例 #5
0
  public NewTaskFrame() throws SQLException {

    this.setModal(true);
    this.setTitle("Create Task"); // title of frame
    this.setSize(400, 350);
    this.setLayout(new BorderLayout()); // layout of frame

    JLabel task_id = new JLabel("ID:");
    JLabel task_name = new JLabel("Name:");
    JLabel task_desc = new JLabel("Description:");

    JLabel priority = new JLabel("Level of Priority:");
    JLabel duedate = new JLabel("Due Date (yyyy-mm-dd)");
    JLabel numberofdays = new JLabel("Number of days required:");
    JLabel skills_required = new JLabel("Skills Required:");

    Object[] id_possibilities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    StringBuffer generated_name = new StringBuffer("t");

    for (int i = 0; i < 6; ++i) {
      generated_name.append(
          id_possibilities[new java.util.Random().nextInt(id_possibilities.length)]);
    }

    task_idfield = new JTextField(generated_name.toString());
    taskname_field = new JTextField();
    taskdesc_field = new JTextArea();

    priority_checkbox = new JCheckBox("High", false);
    numberofdays_field = new JTextField();

    format = new SimpleDateFormat("dd-MM-yyyy"); // set format
    duedate_field = new JFormattedTextField(format);

    // set the duedatefield to tomorrow (since minimum task length = 1)
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.setTime(new Date()); // get current date
    cal.add(Calendar.DAY_OF_MONTH, 1); // add 1 to current date
    Date date = cal.getTime(); // get this date
    duedate_field.setValue(date); // set this date to the field

    // panel to hold labels and text fields
    JPanel labeltextpanel = new JPanel();
    labeltextpanel.setLayout(new GridLayout(7, 2));
    labeltextpanel.add(task_id);
    labeltextpanel.add(task_idfield);
    labeltextpanel.add(task_name);
    labeltextpanel.add(taskname_field);
    labeltextpanel.add(task_desc);
    labeltextpanel.add(taskdesc_field);
    labeltextpanel.add(priority);
    labeltextpanel.add(priority_checkbox);
    labeltextpanel.add(numberofdays);
    labeltextpanel.add(numberofdays_field);
    labeltextpanel.add(duedate);
    labeltextpanel.add(duedate_field);
    labeltextpanel.add(skills_required);

    this.getSkills();

    // main panel for frame including its layout
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(labeltextpanel, BorderLayout.CENTER);

    // buttons
    clear_button = new JButton("Clear");
    submit_button = new JButton("Submit");

    // add listeners to buttons
    clear_button.addActionListener(this);
    submit_button.addActionListener(this);

    // create panel for buttons and add buttons
    JPanel buttonpanel = new JPanel();
    buttonpanel.setLayout(new FlowLayout());
    buttonpanel.add(clear_button);
    buttonpanel.add(submit_button);

    JPanel checkbox_panel = new JPanel();
    checkbox_panel.setLayout(new FlowLayout());

    for (int i = 0; i < skill_list.size(); i++) {
      checkbox_panel.add(skill_list.get(i)); // make this panel flowlayout
    }

    scrollpane = new JScrollPane(checkbox_panel);
    scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(mainPanel, BorderLayout.CENTER);
    panel.add(scrollpane, BorderLayout.SOUTH);
    // add the main panel to main frame

    add(panel, BorderLayout.CENTER);
    add(buttonpanel, BorderLayout.SOUTH);

    this.setVisible(true);
  }
コード例 #6
0
ファイル: test.java プロジェクト: taepeep/AccountingNote
class DatePicker {
  int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
  int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
  JLabel l = new JLabel("", JLabel.CENTER);
  String day = "";
  JDialog d;
  JButton[] button = new JButton[49];

  public DatePicker(JFrame parent) {
    d = new JDialog();
    d.setModal(true);
    String[] header = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
    JPanel p1 = new JPanel(new GridLayout(7, 7));
    p1.setPreferredSize(new Dimension(430, 120));

    for (int x = 0; x < button.length; x++) {
      final int selection = x;
      button[x] = new JButton();
      button[x].setFocusPainted(false);
      button[x].setBackground(Color.white);
      if (x > 6)
        button[x].addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                day = button[selection].getActionCommand();
                d.dispose();
              }
            });
      if (x < 7) {
        button[x].setText(header[x]);
        button[x].setForeground(Color.red);
      }
      p1.add(button[x]);
    }
    JPanel p2 = new JPanel(new GridLayout(1, 3));
    JButton previous = new JButton("<< Previous");
    previous.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            month--;
            displayDate();
          }
        });
    p2.add(previous);
    p2.add(l);
    JButton next = new JButton("Next >>");
    next.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            month++;
            displayDate();
          }
        });
    p2.add(next);
    d.add(p1, BorderLayout.CENTER);
    d.add(p2, BorderLayout.SOUTH);
    d.pack();
    d.setLocationRelativeTo(parent);
    displayDate();
    d.setVisible(true);
  }

  public void displayDate() {
    for (int x = 7; x < button.length; x++) button[x].setText("");
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM yyyy");
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(year, month, 1);
    int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
    int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
    for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++)
      button[x].setText("" + day);
    l.setText(sdf.format(cal.getTime()));
    d.setTitle("Date Picker");
  }

  public String setPickedDate() {
    if (day.equals("")) return day;
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(year, month, Integer.parseInt(day));
    return sdf.format(cal.getTime());
  }
}