hi, i am trying to build a simple program where system asking info (name,age,sex & location) to make a table using do-while loop.
for each info will create one new row in table that i dont know how to make..
please help me...
here, i made for one single row only:
public static void main (String args[])
{
String name, age, sex, location, ans;
Scanner scanner=new Scanner(System.in);
do {
System.out.print("Name: ");
name=scanner.next();
System.out.print("Age: ");
age=scanner.next();
System.out.print("Gender: ");
sex=scanner.next();
System.out.print("Location: ");
location=scanner.next();
System.out.print("Do you want another input?? YES / NO:") ;
ans=scanner.next();
}
while (ans.equals("yes"));
System.out.print("Here is the full data");
JFrame frame=new JFrame("TABLE");
JPanel panel=new JPanel();
panel.setLayout(new BorderLayout());
DefaultTableModel model= new DefaultTableModel();
Vector<String> vCol = new Vector<String>();
vCol.addElement("Name"); vCol.addElement("Age"); vCol.addElement("Sex"); vCol.addElement("Location");
Vector<String> row= new Vector<String>();
row.addElement(name); row.addElement(age); row.addElement(sex); row.addElement(location);
Vector<Vector> vRow=new Vector<Vector>();
vRow.addElement(row);
model = new DefaultTableModel(vRow, vCol);
JTable table = new JTable(model);
JScrollPane scrollpane = new JScrollPane(table);
panel.add(scrollpane, BorderLayout.CENTER);
frame.add(panel);