Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //global scope
- DefaultTableModel model = new DefaultTableModel();
- String[] colomnNames = { "First name", "Second name", "Last name",
- "Address", "Phone", "Age", "Gender" };
- //in constructor
- model.setColumnCount(7);
- model.setColumnIdentifiers(colomnNames);
- jTable1.setEnabled(false);
- //on button click
- Object[] obj = new Object[7];
- obj[0] = nameField.getText();
- // nameField.setText(""); /!!! za wsi4ki nadolu
- obj[1] = nameField1.getText();
- obj[2] = nameField2.getText();
- obj[3] = phoneField.getText();
- obj[4] = addressField.getText();
- obj[5] = ageComboBox.getSelectedItem();
- if (male.isSelected()) obj[6] = male.getText();
- else obj[6] = female.getText();
- // spiner.setValue(2);
- // combo.setSelectedIndex(0);
- // double av = (mark1 + mark2 + mark3) / 3;
- model.addRow(obj);
- //other useful
- String name = f1.getText();
- String fam = f2.getText();
- if(name==null||name==""||fam==""||fam==null||
- (!radio1.isSelected() && !radio2.isSelected())){
- JOptionPane.showMessageDialog(rootPane, "Моля попълнете цялата информация",
- "Грешка", JOptionPane.ERROR_MESSAGE);
- return;
- }
- //
- private void calculate(){
- double srUspeh=0;
- int redCount=0;
- int zadCount=0;
- if(myModel.getRowCount()==0) return;
- for(int i=0;i<myModel.getRowCount()-1;i++){
- srUspeh += (Double)myModel.getValueAt(i, 2);
- if(myModel.getValueAt(i, 3).equals("Редовно")){
- redCount++;
- }
- else zadCount++;
- }
- srUspeh /= myModel.getRowCount();
- usField.setText(String.valueOf(srUspeh));
- redField.setText(String.valueOf(redCount));
- zadField.setText(String.valueOf(zadCount));
- }
Advertisement
Add Comment
Please, Sign In to add comment