Question: Where and what are the sorting algorithms codes to be put in the codes below so that when the table is display it has the
Where and what are the sorting algorithms codes to be put in the codes below so that when the table is display it has the surname and name in alphabetical order?
part of codes is given below:
private void btnaddActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(txtname.getText().equals("")||txtsurname.getText().equals("")||txtage.getText().equals("")){ JOptionPane.showMessageDialog(this, "Please enter all data"); }else{ String data[]= {txtname.getText(),txtsurname.getText(), txtage.getText() }; DefaultTableModel tblModel= (DefaultTableModel)jTableExport.getModel(); tblModel.addRow(data); JOptionPane.showMessageDialog(this, "Data added successfully"); txtname.setText(""); txtsurname.setText(""); txtage.setText(""); } }
private void jButtonExportActionPerformed(java.awt.event.ActionEvent evt) { String filePath = "C:/Users/omar/Desktop/myfolder/txtfile.txt"; File file = new File(filePath);
if (!file.exists()) { try { file.createNewFile(); } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } }
BufferedWriter bw = null; FileWriter fw = null; try { fw = new FileWriter(file); bw = new BufferedWriter(fw);
for(int i = 0; i < jTableExport.getRowCount(); i++){//rows for(int j = 0; j < jTableExport.getColumnCount(); j++){//columns Object value = jTableExport.getValueAt(i, j); if (value != null) { bw.write(value.toString() + " "); }
} bw.newLine(); } } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (bw != null) { bw.close(); } if (fw != null) { fw.close(); } } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
