将java程序集成到jsf中

时间:2015-06-22 06:13:48

标签: java jsf xhtml

我有进度条(swing)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代码上集成(显示)此进度条。

请帮我解决这个问题.. Thanku

1 个答案:

答案 0 :(得分:0)

您可以使用applet,首先尝试创建applet并生成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>

代码:类的名称。

archive:指定存档文件的位置(在示例中,我将jar和xhtml页面放在同一文件夹中)。