API Jena - 按钮“下一步”我的界面无法正常工作
我用的是耶拿。我创建了一个接口,允许在 rdf 文件中添加、修改和删除实例。我对“下一步”按钮有疑问。它有效,但并不完美。我希望它在到达最后一个实例时返回到第一个实例。但它不会这样做,当它到达最后一个实例时,每次按下“下一步”按钮时,它都会重复最后一个实例。我该如何解决这个问题?
这是我的下一步按钮的片段代码:
//Button Next
class ActionSuivant implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
++indice;
ExtendedIterator instances=onto.personne.listInstances();
Individual instance = null;
for(p = 0; p < indice && instances.hasNext(); p++)
{
instance = (Individual) instances.next();
}
tabTF[0].setText(instance.getPropertyValue(onto.aPourPrenom).toString());
tabTF[1].setText(instance.getPropertyValue(onto.aPourNom).toString());
tabTF[2].setText(instance.getPropertyValue(onto.aDateNaiss).toString());
tabTF[3].setText(instance.getPropertyValue(onto.aGenre).toString());
}
}
I'm using Jena. I created an interface that allows to add, modify and remove instances in rdf file. I have a problem with Button Next. It works but not perfectly. I would like that it returns to the first instance when it reaches the last instance. But it does not do this, when it reaches the last instances, it repeats this last instance every time button Next is pressed. How can I solve this?
Here is my fragment code for button next:
//Button Next
class ActionSuivant implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
++indice;
ExtendedIterator instances=onto.personne.listInstances();
Individual instance = null;
for(p = 0; p < indice && instances.hasNext(); p++)
{
instance = (Individual) instances.next();
}
tabTF[0].setText(instance.getPropertyValue(onto.aPourPrenom).toString());
tabTF[1].setText(instance.getPropertyValue(onto.aPourNom).toString());
tabTF[2].setText(instance.getPropertyValue(onto.aDateNaiss).toString());
tabTF[3].setText(instance.getPropertyValue(onto.aGenre).toString());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 for 循环结束时,如果 p 仍然小于 indice,则意味着您已到达列表的末尾。将索引重置为 1,并返回迭代器的第一个元素。
在获取实例的属性之前,您还应该确保该实例不为空。
如果您有一个列表而不是迭代器,那就更容易了:您可以简单地通过索引访问元素。
At the end of your for loop, if p is still less than indice, then it means that you have reached the end of the list. Reset the indice to 1, and return the first element of the iterator.
You should also make sure that instance is not null before getting its properties.
It would be easier if you had a List rather than an Iterator: you could simply access the element by index.