I have a simple swing window in order to load files.
我有一个简单的摆动窗口,以加载文件。
This appear in the class analyzedLoad
, in a function analyzedloads()
这出现在被分析的类中,在函数analyzeloads()中出现
JFileChooser fc = new JFileChooser();
JFrame frame = new JFrame();
int returnVal = fc.showOpenDialog(frame);
frame.dispose();
if (returnVal == JFileChooser.APPROVE_OPTION) {
Where I apply the function without get an input from the user, all fine. But where I get an input from the user, in this way:
我在没有得到用户输入的情况下应用函数,一切都很好。但是我从这里获得了用户的输入,这样:
int al= 0;
Scanner in = new Scanner(System.in);
System.out.println("for choose file, press 1; for save, press 2");
al= in.nextInt();
if (al== 1){
analyzedLoad.analyzedloads(); // A static function which open the swing window
The window doesn't appear, and the process continue to run, without doing anything.
窗口没有出现,进程继续运行,没有做任何事情。
Thanks.
3 个解决方案
#1
2
Becaue "a scanning operation may block waiting for input," I suspect you're blocking the event dispatch thread. Instead use a File Chooser to obtain a file reference.
Becaue“扫描操作可能阻止等待输入,”我怀疑你是阻止了事件发送线程。而是使用文件选择器来获取文件引用。
#2
1
Try adding a second mywindow.setVisible(true)
after the console operation.
尝试在控制台操作后添加第二个mywindow.setVisible(true)。
#3
1
You might want to try to declaring the analyzeLoad
variable as final
and do something like so:
您可能想尝试将analyzeLoad变量声明为final,并执行以下操作:
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
analyzedLoad.analyzedloads();
}
}
or since the method is static:
或者因为该方法是静态的:
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
YourClass.analyzedloads();
}
}
That being said, without more code we can only speculate.
话虽这么说,没有更多的代码,我们只能推测。
#1
2
Becaue "a scanning operation may block waiting for input," I suspect you're blocking the event dispatch thread. Instead use a File Chooser to obtain a file reference.
Becaue“扫描操作可能阻止等待输入,”我怀疑你是阻止了事件发送线程。而是使用文件选择器来获取文件引用。
#2
1
Try adding a second mywindow.setVisible(true)
after the console operation.
尝试在控制台操作后添加第二个mywindow.setVisible(true)。
#3
1
You might want to try to declaring the analyzeLoad
variable as final
and do something like so:
您可能想尝试将analyzeLoad变量声明为final,并执行以下操作:
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
analyzedLoad.analyzedloads();
}
}
or since the method is static:
或者因为该方法是静态的:
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
YourClass.analyzedloads();
}
}
That being said, without more code we can only speculate.
话虽这么说,没有更多的代码,我们只能推测。