繁体   English   中英

将java程序集成到jsf中

[英]to integrate java program into jsf

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

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

您可以使用小程序,首先尝试创建小程序并生成 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 页面放在同一文件夹中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM