JAVA有几种方式来显示进度条
请最好举例说明一下啊
谢谢了
请最好举例说明一下啊
谢谢了
解决方案 »
- 如何指定程序运行自己的security 类
- 这里的多线程中的sleep方法为什么不能用?我加了try和catch,还是不行?
- 一个关于Scanner类中next()和nextLine()方法的问题
- Java开发邮件服务器
- 将table 变成透明
- 谁去过cognosense面试过,他的笔试难不难呀
- JDK5.0怎么去除类型转换的警告?
- 输入流问题!
- 请大家帮忙看下这个Date的问题,解决马上给分~
- 请问rational最新版本支持j2se 1.4.*吗?在哪里可以得到最新版本?
- JFileChoser 问题 大家帮忙啊 谢谢!!!!!!!!!!!
- System.arraycopy的要怎么实现啊?
我把我的代码给你发一下 可以帮我看下吗??谢谢了!!!
import javax.media.*;
import javax.swing.JFrame;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.event.*;
import javawork.swing.*;
import java.awt.Container;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import java.io.IOException; public class VideoPlayer extends JFrame
{ public VideoPlayer()
{ fileToBeAdded.addActionListener(new fileListener());
files.add(fileToBeAdded);
super.setTitle(fileURL);
System.out.println(fileURL);
bar.add(files);
JPanel p = new JPanel();
p.add(bar);
Container cp = getContentPane();
cp.add(p);
System.out.println(fileURL); }
private JMenuItem fileToBeAdded = new JMenuItem( "open ");
private JMenu files = new JMenu( "file ");
private JMenuBar bar = new JMenuBar();
private String fileURL=null;
private Player player = null;
private MediaLocator sourceLocator = null;
class fileListener implements ActionListener
{ public void actionPerformed(ActionEvent e)
{ JFileChooser jFileChooser = new JFileChooser();
int val=jFileChooser.showOpenDialog(VideoPlayer.this);
if(val==JFileChooser.APPROVE_OPTION)
{
String fileDir = jFileChooser.getCurrentDirectory().toString();
String fileName = jFileChooser.getSelectedFile().getName();
fileURL = "file:/// "+fileDir+ "\\ "+fileName;
// fileURL = " "+fileDir+ "\\ "+fileName;
System.out.println(fileURL);
}
sourceLocator = new MediaLocator(fileURL);
try
{
player = Manager.createPlayer(sourceLocator);
// player.addControllerListener(new controlListener());
}catch(IOException iOe)
{
iOe.printStackTrace();
}
catch(NoPlayerException pe)
{
}
player.start();
}
} public static void main(String [] args)
{
Console.run(new VideoPlayer(),80,40);
}
}
这是上面那个程序要引入的 import javawork.swing.*;
package javawork.swing;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*; public class Console {
// Create a title string from the class name:
public static String title(Object o) {
String t = o.getClass().toString();
// Remove the word "class ":
if(t.indexOf( "class ") != -1)
t = t.substring(6);
return t;
}
public static void
run(JFrame frame, int width, int height) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
public static void
run(JApplet applet, int width, int height) {
JFrame frame = new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void
run(JPanel panel, int width, int height) {
JFrame frame = new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width, height);
frame.setVisible(true);
}
} ///:~
用JScrollPane 怎么做啊
* @(#)ProgressTest.java
*
*
* @author 张栋芳QQ271536394
* @version 1.00 2008/3/13
*/import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JProgressBar;
public class ProgressTest extends JDialog{
public JProgressBar jpb;
public int Max=100;
public int Min=0;
public int Count=1;
public JButton bStart;
public ProgressTest() {
Container con=(JPanel)this.getContentPane();
con.setLayout(null);
bStart=new JButton("开始");
bStart.setBounds(10,10,70,30);
bStart.addActionListener(new MyActionListener());
jpb=new JProgressBar();
jpb.setBounds(80,20,300,20);
jpb.setMaximum(Max);
jpb.setMinimum(Min);
jpb.setAutoscrolls(true);
jpb.setStringPainted(true);//进度字
//jpb.setValue(50);
con.add(bStart);
con.add(jpb);
this.setSize(400,300);
this.setTitle("进度条的小程序");
this.setLocationRelativeTo(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args){
ProgressTest test=new ProgressTest();
}
private class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource().equals(bStart)){
System.out.println ("ok");
UpThread thread=new UpThread();
thread.start();
}
}
}
class UpThread extends Thread{
public UpThread(){ }
public void run(){
Count=Min;
while(Count<=Max){
Count++;
jpb.setValue(Count);
try{
if(Count<40){
this.sleep(50);
}
if(Count>=40&&Count<70){
this.sleep(200);
}
if(Count>=70){
this.sleep(50);
}
}catch(Exception ae){
ae.printStackTrace();
}
}
}
}}