⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capanel.java

📁 weka机器学习系统(本站可下载)的拓展
💻 JAVA
字号:
package com.prcomps.cahitarf.gui;

import javax.swing.JPanel;
import javax.swing.ImageIcon;
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;

/**
 *  A very simple extension of JPanel which adds getImageIcon() method.
 */
public class CAPanel
        extends JPanel
{

    /**
     * Retrieves an image as javax.swing.ImageIcon from a given resource path
     * @param path - Resource path URL
     * @return A new ImageIcon instance
    */
    protected ImageIcon getImageIcon( String path )
    {
        URL url = getClass().getClassLoader().getResource( path );
        return new ImageIcon( url );
    }

    public static void launchW32AssocProgram(String extension, String fileName)
            throws IOException
    {
        String command = null;
        StringBuffer fileType = new StringBuffer(20);
        StringBuffer program = new StringBuffer(50);
        InputStream stdOut = null;
        if(command == null)
        {
            Process p = Runtime.getRuntime().exec("cmd /c assoc " + extension);
            stdOut = p.getInputStream();
            boolean collecting = false;
            int i;
            while((i = stdOut.read()) != -1)
            {
                char c = (char)i;
                if(c != '\r' && c != '\n')
                    if(collecting)
                        fileType.append(c);
                    else
                    if(c == '=')
                        collecting = true;
            }

            p = Runtime.getRuntime().exec("cmd /c ftype " + fileType.toString());
            stdOut = p.getInputStream();

            collecting = false;
            int b;
            while((b = stdOut.read()) != -1)
            {
                char c = (char)b;
                if(c != '\r' && c != '\n')
                    if(collecting)
                        program.append(c);
                    else
                    if(c == '=')
                        collecting = true;
            }
            command = program.toString();
        }
        String fullProgramName = program.toString();
        String runProgramName;
        if(program.toString().indexOf("%1")>0)
            runProgramName = fullProgramName.substring(0, fullProgramName.lastIndexOf("%1") - 1);
        else
        if(program.toString().indexOf("\"%L\"")>0)
            runProgramName = fullProgramName.substring(0, fullProgramName.lastIndexOf("\"%L\"") - 1);
        else
            runProgramName = program.toString();
        Runtime r = Runtime.getRuntime();

        r.exec( runProgramName + " \"" + fileName + "\"" );
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -