コード例 #1
0
ファイル: CurvedGaussian.java プロジェクト: Rygbee/CiteSeerX
  public void EMpar(Database db, double prior) {
    int j, np;
    double x, y, tmp, tmpx, tmpy, tmpsx, tmpsy, tmpsxy;

    np = db.nPoints();
    tmpsx = tmpsy = tmpsxy = kmx = kmy = 0;
    for (j = 0; j < np; j++) {
      x = db.xVal(j);
      y = db.yVal(j);
      kmx += probs[j] * x;
      kmy += probs[j] * y;
      tmpsx += probs[j] * x * x;
      tmpsy += probs[j] * y * y;
      tmpsxy += probs[j] * x * y;
    }
    tmp = np * weight;
    kmx /= tmp;
    kmy /= tmp;
    ksx = Math.sqrt(tmpsx / tmp - kmx * kmx);
    ksy = Math.sqrt(tmpsy / tmp - kmy * kmy);
    ksxy = tmpsxy / tmp - kmx * kmy;
    if (ksx < mins) ksx = mins;
    if (ksy < mins) ksy = mins;
    weight = 0.9 * weight + 0.1 * prior;
  }
コード例 #2
0
  // Fees update method
  private void updateFeesData(long id) {
    String columns[] = {"Course", "Fees Payed", "Total fees", "Installments"};
    try {
      Database db = new Database();

      panel_7.removeAll();

      feestablemodel = new MyTableModel(db.getFeeData(id), columns);

      feestable = new JTable(feestablemodel);
      feestable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      feestable.getSelectionModel().addListSelectionListener(this);

      feesscrollpane = new JScrollPane(feestable);
      panel_7.add(feesscrollpane);

      // change fees payed label
      feespayedlabel.setText("Fees Payed");
      feesduelabel.setText("Fees Due");
      totalfeeslabel.setText("Total Fees");

      panel_7.revalidate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #3
0
ファイル: FileMenuHandler.java プロジェクト: cglass102/cs212
  /**
   * opens the chosen file, reads in the file, and prints out a receipt
   *
   * @param chosenFile
   */
  private void readSource(File chosenFile) {
    String chosenFileName = chosenFile.getName();
    TextFileInput inFile = new TextFileInput(chosenFileName);
    Container myContentPane = jframe.getContentPane();
    // chosenFile TextArea myTextArea = new TextArea();
    myContentPane.add(myTextArea);

    int count = 0;
    float priceTotal = 0.0f;
    Database db = new Database("database2.txt");
    String[] transaction = new String[100];
    String line = inFile.readLine();
    DecimalFormat df = new DecimalFormat("#00.00");
    while (line != null) {
      StringTokenizer tokenized = new StringTokenizer(line, ",");
      String code = tokenized.nextToken();
      float weight = Float.parseFloat(tokenized.nextToken());
      String name;
      float price;

      try {
        name = db.getName(code);

      } catch (ItemNotFoundException e) {
        name = JOptionPane.showInputDialog(null, "Item " + code + " not found. Enter Name: ");
      }
      try {
        price = db.getPrice(code);
      } catch (ItemNotFoundException e) {
        price =
            Float.valueOf(
                JOptionPane.showInputDialog(
                    null, "Price for " + name + " not found. Enter price: "));
      }
      float itemTotal = weight * price;
      priceTotal += itemTotal;
      transaction[count] =
          name + "\t" + price + "\t" + df.format(weight) + "\t $" + df.format(itemTotal);
      count++;
      line = inFile.readLine();
    } // while
    myTextArea.setText("ITEM: \t PRICE\\LB: \t POUNDS: \t TOTAL:");
    myTextArea.append("\n");
    for (int i = 0; i < count; i++) {
      myTextArea.append(transaction[i]);
      myTextArea.append("\n");
    }
    myTextArea.append("\t\t   TOTAL: $" + df.format(priceTotal));
    jframe.setVisible(true);
  } // openFile
コード例 #4
0
  // Add fee method
  private void addFees() {
    try {
      float feesadded = Float.parseFloat(addfeestextfield.getText());

      int id = table.getSelectionModel().getMinSelectionIndex();
      long studentid = (long) table.getValueAt(id, 0);

      int index = feestable.getSelectionModel().getMinSelectionIndex();
      String coursename = (String) feestable.getValueAt(index, 0);

      Database db = new Database();
      db.addFees(feesadded, studentid, coursename);

      updateFeesData(studentid);

      addfeestextfield.setText("");
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #5
0
  // Add course method
  public void addCourse() {
    try {
      Database db = new Database();

      String coursename = (String) coursecombobox.getSelectedItem();
      if (coursecombobox.getSelectedIndex() == 0) {
        throw new Exception("No course selected");
      }

      float fees = db.getCoursefees(coursename);
      float totalfees = fees + (ims.main.Settings.getInstallment() * (int) spinner.getValue());

      long id = (long) table.getValueAt((int) table.getSelectionModel().getMinSelectionIndex(), 0);

      db.addCourseToCurrentStudent(id, totalfees, (int) spinner.getValue(), coursename);

      updateFeesData(id);
      courseReset();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #6
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == selectOutfit) {

      setContentPane(frontEndPane);
      startFrontEndPane = null; // not used after button is pressed

      buttonHolder.add(replaceOutfit);
      topPanel.add(db.getItem("Trousers"));
      topPanel.add(db.getItem("T-Shirts"));
      topPanel.add(db.getItem("Jackets"));
      topPanel.add(db.getItem("Shoes"));
      topPanel.add(db.getItem("Sweaters"));
      showTotalPrice(true); // displays the price of selected items on right
      showTotalPrice(false); // displays total price of all items on left
    }

    // Suggest all 5 clothes categories again
    // if replace button is pressed
    if (e.getSource() == replaceOutfit) {
      // if clothesItem topPanel is NOT checked
      if (!((ClothesItem) topPanel.getComponent(0))
          .isChecked()) { // remove 0 element, 1 element, and so on..
        topPanel.remove(0);
        // topPanel gets the next trousers from the database
        topPanel.add(db.getItem("Trousers"), 0);
      }

      if (!((ClothesItem) topPanel.getComponent(1)).isChecked()) {
        topPanel.remove(1);
        topPanel.add(db.getItem("T-Shirts"), 1);
      }

      if (!((ClothesItem) topPanel.getComponent(2)).isChecked()) {
        topPanel.remove(2);
        topPanel.add(db.getItem("Jackets"), 2);
      }

      if (!((ClothesItem) topPanel.getComponent(3)).isChecked()) {
        topPanel.remove(3);
        topPanel.add(db.getItem("Shoes"), 3);
      }

      if (!((ClothesItem) topPanel.getComponent(4)).isChecked()) {
        topPanel.remove(4);
        topPanel.add(db.getItem("Sweaters"), 4);
      }
      showTotalPrice(true);
      showTotalPrice(false);
    }

    if (e.getSource() == help) {
      totalPrice.setText(
          "Pressed Help, press \"Replace\" to switch clothes already shown and unchecked");
    }

    if (e.getSource() == exit) {
      totalPrice.setText("Exiting...");
      this.dispose();
    }

    if (e.getSource() == total) {
      showTotalPrice(false);
    }
  }
コード例 #7
0
ファイル: BodyPan.java プロジェクト: UlTMATE/Lookout
  public void setContent(String cat) {
    cat = cat.trim();
    selectAllCB.setVisible(false);
    selectAllCB.setSelected(false);
    deleteBut.setVisible(false);
    restoreBut.setVisible(false);
    refreshBut.setVisible(true);
    Object columns[] = null;
    int count = 0;
    switch (cat) {
      case "Inbox":
        columns = new Object[] {"", "From", "Date", "Subject", "Content"};
        count = Database.getCount("Inbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc");
        ;
        break;
      case "SentMail":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Sentmail");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc");
        break;
      case "Draft":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Draft");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc");
        break;
      case "Outbox":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Outbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc");
        break;
      case "Trash":
        //                restoreBut.setVisible(true);
        columns = new Object[] {"", "To/From", "Date", "Subject", "Content"};
        count = Database.getCount("Trash");
        workingSet =
            db.getData(
                "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc");
        break;
      default:
        System.out.println("in default case");
    }
    if (count > 0) {
      selectAllCB.setVisible(true);
      rows = new Object[count][];
      msgID = new int[count];
      try {
        workingSet.beforeFirst();
        for (int i = 0; i < count && workingSet.next(); i++) {
          msgID[i] = workingSet.getInt(1);
          rows[i] =
              new Object[] {
                false,
                workingSet.getString(2),
                workingSet.getDate(3),
                workingSet.getString(4),
                workingSet.getString(5)
              };
        }
      } catch (SQLException sqlExc) {
        JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE);
        sqlExc.printStackTrace();
      }

      tableModel = new MyDefaultTableModel(rows, columns);
      table = new JTable(tableModel);
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(this);
      table.getTableHeader().setOpaque(true);
      table.getTableHeader().setReorderingAllowed(false);
      //            table.getTableHeader().setBackground(Color.blue);
      table.getTableHeader().setForeground(Color.blue);
      //        table.setRowSelectionAllowed(false);
      //            table.setColumnSelectionAllowed(false);
      table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
      table.setRowHeight(20);
      table.setFillsViewportHeight(true);

      TableColumn column = null;
      for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
          column.setPreferredWidth(6);
        } else if (i == 3) {
          column.setPreferredWidth(250);
        } else if (i == 4) {
          column.setPreferredWidth(450);
        } else {
          column.setPreferredWidth(40);
        }
      }
      table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

      remove(contentPan);
      contentPan = new JScrollPane(table);
      contentPan.setBackground(Color.orange);
      contentPan.setOpaque(true);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      Home.home.homeFrame.setVisible(true);
    } else {
      JPanel centPan = new JPanel(new GridBagLayout());
      centPan.setBackground(new Color(52, 86, 70));
      JLabel label = new JLabel("No Messages In This Category");
      label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
      label.setForeground(Color.orange);
      centPan.add(label);
      remove(contentPan);
      contentPan = new JScrollPane(centPan);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      contentPan.repaint();
    }
  }
コード例 #8
0
ファイル: BodyPan.java プロジェクト: UlTMATE/Lookout
  @Override
  public void actionPerformed(ActionEvent axnEve) {
    Object obj = axnEve.getSource();

    if (obj == selectAllCB) {
      Boolean state;
      if (selectAllCB.isSelected()) {
        state = true;
        deleteBut.setVisible(true);
        if (Home.titlePan.getTitle().equals("Trash")) {
          restoreBut.setVisible(true);
        }
      } else {
        state = false;
        deleteBut.setVisible(false);
        if (Home.titlePan.getTitle().equals("Trash")) {
          restoreBut.setVisible(false);
        }
      }
      for (int i = 0; i < table.getRowCount(); i++) {
        table.setValueAt(state, i, 0);
      }
    } else if (obj == refreshBut || obj == backBut) {
      setContent(Home.titlePan.getTitle());
      backBut.setVisible(false);
    } else if (obj == deleteBut) {
      ArrayList selectedMessages = getSelectedMessages();
      if (selectedMessages.isEmpty()) {
        FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE);
      } else {
        int option =
            JOptionPane.showConfirmDialog(
                Home.home.homeFrame,
                "Are You Sure?",
                "DELETE",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE);
        if (option == 0) {
          Database.deleteMessages(selectedMessages, Home.titlePan.getTitle());
          setContent(Home.titlePan.getTitle());
        }
      }
    } else if (obj == restoreBut) {
      ArrayList selectedMessages = getSelectedMessages();
      if (selectedMessages.isEmpty()) {
        FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE);
      } else {
        int option =
            JOptionPane.showConfirmDialog(
                Home.home.homeFrame,
                "Are You Sure?",
                "RESTORE",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE);
        if (option == 0) {
          Database.restoreMessages(selectedMessages);
          setContent(Home.titlePan.getTitle());
        }
      }
    }
  }
コード例 #9
0
 public void update_table() {
   Database.showDB("transaction", transaction_column, info_data, info_table);
 }
コード例 #10
0
 public void update_table() {
   Database.showDB("member", member_column, info_data, info_table);
 }
コード例 #11
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void initializeComponent() {
    // Initialize panels
    panel_1 = new JPanel();
    panel_2 = new JPanel();
    panel_3 = new JPanel();
    panel_4 = new JPanel();
    panel_5 = new JPanel();
    panel_6 = new JPanel();
    panel_7 = new JPanel();

    // Initialize spinner
    spinnermodel = new SpinnerNumberModel(0, 0, 10, 1);
    spinner = new JSpinner(spinnermodel);

    // Initialize combo box
    searchcombobox = new JComboBox();
    searchcombobox.addItem("All");
    searchcombobox.addItem("By Name");
    searchcombobox.addItem("By Guardian Name");
    searchcombobox.addItem("By Course");
    searchcombobox.addItem("Due Fees");
    searchcombobox.setSelectedIndex(0);

    coursecombobox = new JComboBox();
    coursecombobox.addItem("Select Course");
    Database db = new Database();
    String courses[] = db.getCourses();

    if (courses != null) {
      for (String x : courses) {
        coursecombobox.addItem(x);
      }
    }

    // Initialize text field
    searchtextfield = new JTextField(10);
    addfeestextfield = new JTextField(8);

    // Initialize button
    searchbutton = new JButton("Search");
    addfeesbutton = new JButton("Add fees");
    addcoursebutton = new JButton("Add Course");

    // Initialize check box
    allfieldcheckbox = new JCheckBox("Show all fields");
    allfieldcheckbox.setSelected(true);

    // Initialize label
    totalstudentlabel = new JLabel("Total Student");
    feespayedlabel = new JLabel("Fees Payed");
    feesduelabel = new JLabel("Fees due");
    totalfeeslabel = new JLabel("Total fees");

    // Add Item listener to check box
    allfieldcheckbox.addItemListener(this);

    // Add Action Listener to button
    searchbutton.addActionListener(this);
    addfeesbutton.addActionListener(this);
    addcoursebutton.addActionListener(this);

    // Add Key Listener to button
    searchbutton.addKeyListener(this);
    addfeesbutton.addKeyListener(this);
    addcoursebutton.addKeyListener(this);
  }
コード例 #12
0
  // Method to update Table and related components
  private void update() {
    Database db = new Database();
    String column[] = {
      "ID",
      "NAME",
      "GENDER",
      "GUARDIAN_ROLE",
      "GUARDIAN_NAME",
      "PRESENT_ADDRESS",
      "PRESENT_CITY",
      "PRESENT_PHONE"
    };

    try {
      // Update table
      if (searchcombobox.getSelectedIndex() == 0 && allfieldcheckbox.isSelected()) {
        mytablemodel = new MyTableModel(db.getAllStudent(), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 0 && !allfieldcheckbox.isSelected()) {
        mytablemodel = new MyTableModel(db.getSomeFieldsFromStudent(), column);
      } else if (searchcombobox.getSelectedIndex() == 1 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE NAME = \'" + searchtextfield.getText().trim() + "\'";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 1 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 2 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE GUARDIAN_NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 2 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE GUARDIAN_NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 3 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'))";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 3 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'))";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 4 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)";
        mytablemodel = new MyTableModel(db.getData(query), column);
      }

      table = new JTable(mytablemodel);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      // Add list selection listener to table
      table.getSelectionModel().addListSelectionListener(this);

      TableColumn col = null;
      for (int i = 3; i < table.getColumnCount(); i++) {
        col = table.getColumnModel().getColumn(i);
        col.setPreferredWidth(200);
      }

      scrollpane = new JScrollPane(table);

      panel_3.removeAll();
      panel_3.add(scrollpane);

      // Update total student label
      int total = db.getTotalStudent();
      totalstudentlabel.setText("Total Student = " + total);

      // Clear search combo box
      searchtextfield.setText("");

      this.revalidate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }