I have a large Java project(a SQL-backed personnel system, in Java 6) with a Text Interface which is fairly complex. For example, in the main class when the user picks the person option, it will call this code:
int choice = new Integer(line);
if(choice >= 1 && choice <= 13){
exit = false;
models[choice - 1].showMenu();
}
And then it eventually calls the Person class, whose constructor looks like this:
public Person(Connection con){
conn = con;
item = "Person";
count = getLastID() + 1;
}
and a sample menu option to get all of a person’s info looks like so:
protected void queryGetAll(){
Statement stmnt = null;
// create prepared statement
try {
stmnt = conn.createStatement();
ResultSet result = stmnt.executeQuery("SELECT * FROM person");
System.out.println("");
System.out.println("");
System.out.println(" ***************** LIST OF ALL PERSONS ***************** ");
System.out.println("");
while(result.next()){
System.out.print(" ID: " + result.getString("per_id") + " | ");
System.out.print(" NAME: " + result.getString("name") + " | ");
System.out.print(" STREET: " + result.getString("street") + " | ");
System.out.print(" CITY: " + result.getString("city") + " | ");
System.out.print(" ZIP CODE: " + result.getString("zip_code") + " | ");
System.out.print(" E-MAIL: " + result.getString("email") + " | ");
System.out.println(" GENDER: " + result.getString("gender"));
}
System.out.println("");
System.out.println("");
stmnt.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
I want to convert this whole TUI into a GUI using NetBeans, which makes GUI building easy. The issue is I don’t know how to “grab” the results, i.e, what do I put in the GUI code here:
this.textBox.setText("The person's information" + iDontKnowWhatsHere );
Is there any work-around here? If it’s possible to grab what by default is put onto the console, and just shoot it to the GUI text-box I’d be happy to do that. Any guidance/tips appreciated, Thanks
I think the most suitable component here is JTable.
Create one Vector of String as columns ‘ names and Vector of Vector for the table data.
Main Vector contain rows (also Vectors) and each rowVector has all the row values.
Then create a DefaultTableModel and a JTable based on the model (JTable also has construtor to pass the columns and data)