[英]How show my application delay with JProgressBar?
I wrote a simple application and I want show delay of it with JProgressBar Plese help me ; 我写了一个简单的应用程序,我想用JProgressBar Plese显示它的延迟;
I want show JProgressBar with Joptionpane , with a cancel button and it should be modal 我想用Joptionpane显示JProgressBar,并带有一个取消按钮,它应该是模态的
this is my source code : 这是我的源代码:
class CustomFrame extends JFrame {
private JProgressBar progressBar;
public CustomFrame() {
long start = System.currentTimeMillis();
myMethod();
this.getContentPane().setLayout(null);
this.setSize(200, 200);
//JOptionPane. ?????
this.setTitle("JFrame");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
long end = System.currentTimeMillis();
System.out.print("\nTime: " + (end - start));
}
public void myMethod(){
try {
java.io.File file = new java.io.File("i://m.txt");
BufferedReader input =
new BufferedReader(new FileReader(file));
String line;
while ((line = input.readLine()) != null) {
if (line.indexOf("CREATE KGCGI=") != -1 ){
System.out.println(line);
}
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
}
Thanks ... 谢谢 ...
There are a couple things that you will need to do to get this to work: 要使它正常工作,您需要做几件事:
file.length()
)to determine how to scope your progress bar ( myProgressBar.setMaximum(length)
) file.length()
),以确定如何调整进度条的范围( myProgressBar.setMaximum(length)
) myProgressBar.setValue(myProgressBar.getValue()+lineLength)
). myProgressBar.setValue(myProgressBar.getValue()+lineLength)
,将需要触发对进度条的更新( myProgressBar.setValue(myProgressBar.getValue()+lineLength)
)。 A couple points by way of critique: 批评的几点:
init()
method. init()
方法的调用中进行。 JFrame
as superclass. JFrame
作为超类正在做什么。 JOptionPane
is a class that will pop up a very basic modal dialog with some text, maybe an icon or input field. JOptionPane
是一个类,它将弹出一个非常基本的模态对话框,其中包含一些文本,可能是图标或输入字段。 It isnt a panel that is embedded in a dialog. JDialog
, which can also be made modal. JDialog
(也可以使其成为模式)可能会更容易。 JDialog
will allow you to add buttons as you please, where as a standalone JOptionPane
will require you to use Yes/No, or Yes/No/Cancel or OK/Cancel etc. JDialog
允许您JDialog
添加按钮,而作为独立JOptionPane
则要求您使用“是/否”或“是/否/取消”或“确定/取消”等。 JOptionPane
, and only show a cancel button, you can instantiate a JOptionPane
(as opposed to using the utility show*
methods), with the progressbar as the message
, and the JOptionPane.CANCEL_OPTION
as the optionType
param. JOptionPane
,并且仅显示取消按钮,则可以实例化JOptionPane
(与使用实用程序show*
方法相对),并使用进度条作为message
,并将JOptionPane.CANCEL_OPTION
用作optionType
参数。 You will still need to put this into a JDialog
to make it visible. JDialog
以使其可见。 See this tutorial for more details: JOptionPane (constructor)
JOptionPane(构造函数)
Creates a JOptionPane with the specified buttons, icons, message, title, and so on.
使用指定的按钮,图标,消息,标题等创建JOptionPane。 You must then add the option pane to a JDialog, register a property-change listener on the option pane, and show the dialog.
然后,您必须将选项窗格添加到JDialog,在选项窗格上注册属性更改侦听器,然后显示对话框。 See Stopping Automatic Dialog Closing for details.
有关详细信息,请参见停止自动关闭对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.