VasilM

nothin in particular

Nov 25th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. //global scope
  2. DefaultTableModel model = new DefaultTableModel();
  3. String[] colomnNames = { "First name", "Second name", "Last name",
  4.                                      "Address", "Phone", "Age", "Gender" };
  5.  
  6. //in constructor      
  7.         model.setColumnCount(7);
  8.         model.setColumnIdentifiers(colomnNames);
  9.         jTable1.setEnabled(false);
  10.  
  11. //on button click
  12.         Object[] obj = new Object[7];
  13.         obj[0] = nameField.getText();
  14.     // nameField.setText(""); /!!! za wsi4ki nadolu
  15.         obj[1] = nameField1.getText();
  16.         obj[2] = nameField2.getText();
  17.         obj[3] = phoneField.getText();
  18.         obj[4] = addressField.getText();
  19.         obj[5] = ageComboBox.getSelectedItem();
  20.         if (male.isSelected()) obj[6] = male.getText();
  21.         else obj[6] = female.getText();
  22.     // spiner.setValue(2);
  23.     // combo.setSelectedIndex(0);
  24.     // double av = (mark1 + mark2 + mark3) / 3;
  25.        
  26.         model.addRow(obj);
  27.  
  28. //other useful
  29.         String name = f1.getText();
  30.         String fam = f2.getText();
  31.         if(name==null||name==""||fam==""||fam==null||
  32.                 (!radio1.isSelected() && !radio2.isSelected())){
  33.             JOptionPane.showMessageDialog(rootPane, "Моля попълнете цялата информация",
  34.                     "Грешка", JOptionPane.ERROR_MESSAGE);
  35.             return;
  36.         }
  37.  
  38. //
  39.         private void calculate(){
  40.         double srUspeh=0;
  41.         int redCount=0;
  42.         int zadCount=0;
  43.         if(myModel.getRowCount()==0) return;
  44.         for(int i=0;i<myModel.getRowCount()-1;i++){
  45.             srUspeh += (Double)myModel.getValueAt(i, 2);
  46.             if(myModel.getValueAt(i, 3).equals("Редовно")){
  47.                 redCount++;
  48.             }
  49.             else zadCount++;
  50.         }
  51.         srUspeh /= myModel.getRowCount();
  52.         usField.setText(String.valueOf(srUspeh));
  53.         redField.setText(String.valueOf(redCount));
  54.         zadField.setText(String.valueOf(zadCount));
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment