The topic says it already. I have a class with an ImageIcon as an attribute.
Now as I am a total newbie and couldn't get this information out of the documentation, I ask myself if this is possible at all?
If it's not possible how could I save images or ImageIcons in the database with the hibernate mapping?
Could you please give me an example how such a mapping file could look like to the following class:
Code:
public class QuestionNode extends OurNode {
private String questionBody = null;
private ArrayList answers = new ArrayList();
private ImageIcon image = null;
/**
* Constructor
* @param name for node
*/
public QuestionNode(String name, long id) {
super(name, id);
}
/**
*
* @param name sets field questionName
* @param qust sets field questionBody
*/
public QuestionNode(String name, String qust) {
super(name);
this.questionBody = qust;
} // end constructor
/**
*
* @param name sets field questionName
* @param qust sets field questionBody
*/
public QuestionNode(String name, String qust, long id, Date dat) {
super(name, id, dat);
this.questionBody = qust;
} // end constructor/**
/**
*
* @return questionBody
*/
public String getQuestionBody() {
return questionBody;
}
/**
*
* @param index indicates which answer has to bei chosen from ArraList answers
* @return answer at index
*/
public Answer getAnswer(int index) {
return (Answer)answers.get(index);
}
/**
* @return indicates which answers are true and which are false
*/
public boolean[] getCorrectAnswer() {
boolean[] correctAnswer = {
((Answer)answers.get(0)).isCorrect(),
((Answer)answers.get(1)).isCorrect(),
((Answer)answers.get(2)).isCorrect(),
((Answer)answers.get(3)).isCorrect()};
return correctAnswer;
}
/**
*
* @return ImageIcon
*/
public ImageIcon getImage() {
return image;
}
/**
*
* @param body set questionBody
*/
public void setQuestionBody(String body) {
questionBody = body;
}
/**
* add a new answer to the ArrayList answers
* @param answer text of the answer
* @param c if answer is true or false
*/
public void addAnswer(String answer, boolean c, String annotation, long ID) {
answers.add(new Answer(answer, c, annotation, ID));
}
/**
* sets answer at index
* @param index which answer is going to be changed
* @param text text of the answer
* @param c if answer is true or false
*/
public void setAnswer(int index, String text, boolean c)
{
((Answer)answers.get(index)).setAnswer(text);
((Answer)answers.get(index)).setCorrect(c);
}//end setAnswer
/**
* sets annotation at index
* @param index index of annotation, actually answer
* @param text text to set annotation to
*/
public void setAnnotation(int index, String text) {
((Answer)answers.get(index)).setAnnotation(text);
}
/**
* add or change the image to the question
* @param ImageIcon to set
*/
public void setImage(ImageIcon ic) {
image = ic;
}
}
The superclass to aboves class look like this:
Code:
public class OurNode extends DefaultMutableTreeNode {
private String name = null;
private String author = null;
private Date dateOfCreation = null; //TODO use sql.Date instead?
private long ID;//TODO id and dateOfCreation from DB
/**
* Constructor
*/
public OurNode() {
this.name = "new OurNode";
this.author = "none";
this.dateOfCreation = new Date();
}
/**
* Constructor
* @param name of the node
*/
public OurNode(String name) {
this.name = name;
this.author = "none";
this.dateOfCreation = new Date();
}
/**
* Constructor
* @param name of the node
*/
public OurNode(String name, long id) {
this.name = name;
this.author = "none";
this.dateOfCreation = new Date();
this.ID = id;
}
/**
* Constructor
* @param name of the node
*/
public OurNode(String name, long id, Date date) {
this.name = name;
this.author = "none";
this.ID = id;
this.dateOfCreation = date;
}
/**
* Set the author of this node
*/
public void setAuthor(String auth) {
this.author = auth;
}
/**
* @return The author of this node
*/
public String getAuthor() {
return this.author;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return name as String
*/
public String toString() {
return name;
}
/**
* @return Returns the id
*/
public long getID() {
return ID;
}
/**
* @return Returns the dateOfCreation.
*/
public Date getDateOfCreation() {
return dateOfCreation;
}
}
thx,
tezem