诡异的。查询可以在 Fuseki HTML 表单中运行,但不能在 JAVA 中运行?
我想请教一些关于线程使用的问题。我查看了很多帖子和这些帖子建议的链接,但仍然一片空白。 我有一个包含几个类的 NetBeans 项目。其中之一是 Gui 类,我只需单击一个按钮即可执行一些处理。我从 Gui 调用另一个类的实例,该类又调用其他类。其中一个类向 TDB 后端数据库提交 Sparql 查询。目前所有输出都保存到文件中。
我想要做的是以某种方式使从 Gui 调用的类在另一个线程上运行,并且还能够从一个或多个被调用的类更新 Gui 上的 EditorPane 和 TextArea。到目前为止,我已经尝试调用 Gui 类的实例并在其中使用公共方法,但这不起作用。我正在调用实例 Gui
Gui gui = new Gui();
gui.setEditorPaneText("File name is: " + fn);
,并且 Gui 类中的方法是
public void setEditorPaneText(final String string) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setString(string);
EditorPane.setText(getString());
EditorPane.repaint();
}
});
}
我尝试运行调试器,但处理从方法的第一行跳到最后一个大括号,而不处理其中的代码。我的 Gui 类具有以下主要方法。评论部分是我在阅读有关该问题的大量帖子时更改的事件队列的先前版本。
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Gui().setVisible(true);
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
以下是我在阅读有关此问题的一些帖子后替换的主要方法的先前代码。
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Gui().setVisible(true);
}
});
任何有用的信息将不胜感激。谢谢。
I would like to ask some questions regarding the use of threads. I have looked at a lot of posts and links suggested from those posts but still came up blank.
I have a NetBeans project that has a few classes. One of them is the Gui class that I use to just click a button and some processing gets performed. From the Gui I call an instance of another class that in turn calls other classes. One of these classes submits a Sparql query to a TDB backend database. All output is saved to files for now.
What I would like to do is to somehow make the class called from the Gui to run on another thread and also to be able to update an EditorPane and a TextArea on the Gui from one or more of the called classes. Up to now I have tried calling an instance of the Gui class and use a public method within but this does not work. I am calling the instance Gui with
Gui gui = new Gui();
gui.setEditorPaneText("File name is: " + fn);
and the method in the Gui class is
public void setEditorPaneText(final String string) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setString(string);
EditorPane.setText(getString());
EditorPane.repaint();
}
});
}
I tried running the debugger but the processing skips from the first line of the method to the last curly bracket without processing the code within. My Gui class has the following as a main method. The commented part was a previous version of the event queue that I changed while I was reading through the numerous posts on the issue.
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Gui().setVisible(true);
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
The following is the previous code of the main method that I replaced after reading some of the posts on this issue.
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Gui().setVisible(true);
}
});
Any helpful information will be much appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的主要错误是您创建了 Gui 类的两个实例。您有两次以下代码片段:
new Gui()
。请看下面我的示例代码,了解如何将 Gui 传递到工作线程的示例。I think your main error is that you create two instances of your Gui class. You have the following snippet twice:
new Gui()
. Take a look at my example code below to see an example how to pass the Gui to your worker thread.