「java图标icon」java图标变红眼

博主:adminadmin 2023-01-29 00:15:10 559

今天给各位分享java图标icon的知识,其中也会对java图标变红眼进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java 如何得到文件的系统图标

java可使用FileSystemView和ShellFolder类获取文件的小图标和大图标,以下是详细代码:

import java.awt.FlowLayout;

import java.io.File;

import java.io.FileNotFoundException;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.filechooser.FileSystemView;

public class GetFileIcon {

/**

 * @param args

 */

    public static void main( String[] args )

    {

        String    filePath    = "D:/sheet1.xlsx";

        File    f        = new File( filePath );

        JFrame    frm        = new JFrame();

        frm.setSize( 300, 200 );

        frm.setLocationRelativeTo( null );

        frm.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        frm.setVisible( true );

        frm.setLayout( new FlowLayout( 10, 10, FlowLayout.LEADING ) );

        JLabel sl = new JLabel( "小图标" );

        frm.add( sl );

        JLabel bl = new JLabel( "大图标" );

        frm.add( bl );

        sl.setIcon( getSmallIcon( f ) );

        bl.setIcon( getBigIcon( f ) );

    }

/**

 * 获取小图标

 * @param f

 * @return

 */

    private static Icon getSmallIcon( File f )

    {

        if ( f != null  f.exists() )

        {

            FileSystemView fsv = FileSystemView.getFileSystemView();

            return(fsv.getSystemIcon( f ) );

        }

        return(null);

    }

/**

 * 获取大图标

 * @param f

 * @return

 */

    private static Icon getBigIcon( File f )

    {

        if ( f != null  f.exists() )

        {

            try {

                sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder( f );

                return(new ImageIcon( sf.getIcon( true ) ) );

            } catch ( FileNotFoundException e ) {

/* TODO Auto-generated catch block */

                e.printStackTrace();

            }

        }

        return(null);

    }

}

java显示ico格式图片

--------------------------------------------------------------------------------------------

import java.awt.Graphics;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class ImageApp extends JFrame {

public ImageApp() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setSize(400, 300);

setResizable(false);

getContentPane().setLayout(null);

JPanel panel = new ImagePanel();

panel.setBounds(0, 0, 400, 300);

getContentPane().add(panel);

setVisible(true);

}

public static void main(String[] args) {

new ImageApp();

}

class ImagePanel extends JPanel {

public void paint(Graphics g) {

super.paint(g);

ImageIcon icon = new ImageIcon("D:\\14405937jqhjsppeninjf9.ico");

g.drawImage(icon.getImage(), 0, 0, 400, 300, this);

}

}

}

java左上角图标不显示

首先,打开java开发工具,MyEclipse工具,添加一个java项目,在这里小编不做图片介绍了

2

/7

进入到Java Project中,引入相关的jar包和import相关的java类,编写一个java awt窗口的java代码,保存代码(要有这个良好的习惯哦)最重要的内容来了,要修改java运行界面左上角的logo图标

你需要在java代码中加入如下两个语句

Image icon = Toolkit.getDefaultToolkit().getImage("G:\\0000分享\\分享\\图片1.jpg"); // 图片的具体位置

jf.setIconImage(icon); //设置窗口的logo保存好新修改的java代码后,再次点击运行java项目,你将会看到如下的效果,java运行界面左上角的logo图标真的就改变了,下面将附上我使用的图片及运行画面效果

java中的icon是什么啊?

java中的icon是属于接口类,主要设置窗口图标,实例如下:

package com.han;

import java.awt.*;

import javax.swing.*;

/**

 * This example shows the drawing of an icon using the Icon interface

 *  for the JLable component.

 * @author han

 *

 */

public class DrawIcon implements Icon{//该类实现该接口icon

private int width;

private int height;

@Override

public int getIconHeight(){

return this.height;

}

@Override

public int getIconWidth(){

return this.width;

}

@Override

public void paintIcon(Component c, Graphics g, int x, int y){

g.setColor(Color.red);

g.fillOval(x, y, width, height);

}

/*the construct function*/

public DrawIcon(int width, int height){

this.width=width;

this.height=height;

}

    public static void main(String[] args){

     DrawIcon icon=new DrawIcon(15,15);

     JLabel jl=new JLabel("测试",icon,SwingConstants.CENTER);

     JFrame jf=new JFrame();

     Container c=jf.getContentPane();

     c.add(jl);

     jf.setVisible(true);

     jf.setSize(300,300);

     jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

}

java怎样获取apk文件icon图标

java获取apk文件icon图标的方法步骤如下:

1、解压apk,apk实际上是zip压缩档。

2、解析AndroidManifest.xml文件,解析application节点,获取android:icon属性,得到图标资源文件名。

3、图标资源大多数位于/drawable-hdpi目录下。

4、尝试读取png或者jpg格式,如果还读取不到,那就按照没有图标处理。

java图标icon的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java图标变红眼、java图标icon的信息别忘了在本站进行查找喔。