我有进度条(摆动)java代码,它以进度条的形式显示硬盘的状态(即已用空间的百分比)。
Java 代码如下:(AutoProgress.java )
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.io.File;
public class AutoProgress extends Throwable {
public static void main(String args[]) {
File[] drives = File.listRoots();
JFrame f = new JFrame("Hard Disk Status");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(drives.length, 1));
JProgressBar[] bar;
bar = new JProgressBar[10];
int i;
Border border;
if (drives != null && drives.length > 0) {
for (i = 0; i < drives.length; i++) {
double temp = 0.0;
bar[i] = new JProgressBar();
double freeSpace = drives[i].getFreeSpace();
double totalSpace = drives[i].getTotalSpace();
double usedSpace = (totalSpace - freeSpace);
totalSpace = totalSpace / (1024 * 1024);
usedSpace = usedSpace / (1024 * 1024);
int perUsed = 0;
if (totalSpace > 0) {
temp = ((usedSpace * 100) / totalSpace);
}
perUsed = (int) Math.round(temp);
bar[i].setValue(perUsed);
bar[i].setStringPainted(true);
border = BorderFactory.createTitledBorder(drives[i].toString());
bar[i].setBorder(border);
f.add(bar[i]);
if (perUsed > 80) {
bar[i].setForeground(Color.red);
}
}
}
f.setSize(500, drives.length * 50);
f.setVisible(true);
}
}
我想在用JSF编写的XHTML代码上集成(显示)这个进度条。
请帮我解决这个问题..谢库
您可以使用小程序,首先尝试创建小程序并生成jar文件,然后将其嵌入到xhtml代码中:
<object classid="clsid:8ad9c840-044e-11d1-b3e9-00805f499d93"
width="300" height="30"
codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_3-win.cab#version=1,3,0,0">
<param name="code" value="ClassName.class" />
<param name="archive" value="JarName.jar" />
<PARAM NAME="MAYSCRIPT" VALUE="true" />
<param name="type"
value="application/x-java-applet;version=1.3">
<comment> <embed
type="application/x-java-applet;version=1.3"
archive="JarName.jar"
code="ClassName.class" width="300"
height="30"
pluginspage="http://java.sun.com/products/plugin/index.html#download">
<noembed></noembed> </embed> </comment>
</param>
</object>
代码:类的名称。
存档:指定存档文件的位置(在示例中,我将jar和xhtml页面放在同一个文件夹中)。