i have a hashMap which i would like its data to be viewed in a JTable how ever i am having trouble getting the hashMap amount of columns and rows and the data to be displayed.i have a hashmap which takes a accountID as the key and a object of students in which each students have their data like name,id, age, etc.however referring to the JTable docs, it says i would need ints for the row and column and a multidimension array of type Object. how can i do it? can i change my hashMap into a multidimenion array?
--Edit i have edited my question so it could be more clear , i am fairly new to Java i do not really get what some of you have posted, especially since the work i am doing is quite related to OO and grasping OO concepts is my biggest challenge,
/I have a dataStorage class, the registered user is added to the HashMap with a Key input of his Username, which is getUser ./
import java.util.*;
public class DataStorage
{
HashMap<String, Student> students = new HashMap<String, Student>();
HashMap<String, Staff> staffMembers = new HashMap<String, Staff>();
//Default constructor
public DataStorage(){
}
public void addStaffMember(Staff aAcc)
{
staffMembers.put(aAcc.getUser(),aAcc);
}
public void addStudentMember(Student aAcc)
{
students.put(aAcc.getUser(),aAcc);
}
public Staff getStaffMember(String user)
{
return staffMembers.get(user);
}
public Student getStudent(String user)
{
return students.get(user);
}
public int getStudentRows()
{
return students.size();
}
}
/** This is a student class which extends Account*/
public class Student extends Account {
private String studentNRIC;
private String diploma;
private String gender;
private double level;
private int credits;
private int age;
private boolean partTime;
private boolean havePc;
private boolean haveChild;
public Student(String n, String nr, String id, String dep, String user, String pass)
{
super(n, dep, user, pass, id);
studentNRIC = nr;
}
public void setPartTime(boolean state)
{
if(state == true)
{
partTime = true;
}
else
{
partTime = false;
}
}
public boolean getPartTime()
{
return partTime;
}
public void setHavePc(boolean state)
{
if(state == true)
{
havePc = true;
}
else
{
havePc = false;
}
}
public boolean getHavePc()
{
return havePc;
}
public void setHaveChild(boolean state)
{
if(state == true)
{
haveChild = true;
}
else
{
haveChild = false;
}
}
public boolean getHaveChild()
{
return haveChild;
}
public void setDiploma(String dip)
{
diploma = dip;
}
public String getDiploma()
{
return diploma;
}
public void setCredits(String cre)
{
credits = Integer.parseInt(cre);
}
public int getCredits()
{
return credits;
}
public void setGender(String g)
{
gender = g;
}
public String getGender()
{
return gender;
}
public void setAge(String a)
{
age = Integer.parseInt(a);
}
public int getAge()
{
return age;
}
public void setLevel(String lvl)
{
level = Double.parseDouble(lvl);
}
public double getLevel()
{
return level;
}
public void setStudentNRIC(String nr)
{
studentNRIC = nr;
}
public String getStudentNRIC()
{
return studentNRIC;
}
}
/** This is a the Account superclass*/
public class Account {
private String name;
private String department;
private String username;
private String password;
private String accountID;
public Account()
{
}
public Account(String nm,String dep,String user,String pass, String accID)
{
name = nm;
department = dep;
username = user;
password = pass;
accountID = accID;
}
public void setName(String nm)
{
name = nm;
}
public String getName()
{
return name;
}
public void setDep(String d)
{
department = d;
}
public String getDep()
{
return department;
}
public void setUser(String u)
{
username = u;
}
public String getUser()
{
return username;
}
public void setPass(String p)
{
password = p;
}
public String getPass()
{
return password;
}
public void setAccID(String a)
{
accountID = a;
}
public String getAccID()
{
return accountID;
}
}