一、遇到的问题 ImageIcon icon = new ImageIcon("logo.jpg"); 执行结果是icon无法显示 二、解决的方案 如果类中有如下调用: ImageIcon icon =...new ImageIcon("logo.jpg"); 很自然地认为当前类文件和图片在同一路径下即可。...所以正确的调用是(cn.fkomm是包名) ImageIcon icon = new ImageIcon("src/cn/fkomm/logo.jpg"); 这行代码执行时在project/test目录下查找到了文件...Public ImageIcon(String filename)//参数可以是绝对路径也可以是相对路径 Public ImageIcon(URL url) 第一种构造不再讲解。...ImageIcon(url); ImageIcon支持GIF、JPG、PNG等格式。
imageIcon = new ImageIcon("..../image/face0.gif"); public static ImageIcon face1 = new ImageIcon("..../image/face1.gif"); public static ImageIcon face2 = new ImageIcon("..../image/mine.gif"); public static ImageIcon mine0 = new ImageIcon("..../image/ask.gif"); public static ImageIcon ask1 = new ImageIcon(".
body = new ImageIcon(bodyURL); private static ImageIcon food = new ImageIcon(Data.class.getResource...("/com/tang/retor_snaker/statics/food.png")); private static ImageIcon up = new ImageIcon(Data.class.getResource...("/com/tang/retor_snaker/statics/up.png")); private static ImageIcon down = new ImageIcon(Data.class.getResource...ImageIcon up) { Data.up = up; } public static ImageIcon getDown() {...(ImageIcon left) { Data.left = left; } public static ImageIcon getRight() {
i = new ImageIcon("8.png"); // 创建一张图片 笼的图片 JLabel target1_Lab = new JLabel(i); // 使用JLabel...i = new ImageIcon("4.png"); // 创建一张图片 羊的图片 JLabel sheep1_Lab = new JLabel(i); // 使用JLabel...i = new ImageIcon("1.png"); for (int j = 0; j < datas.length; j++) { for (int k...i = new ImageIcon("-10.png"); wolf_lab = new JLabel(i); wolf_lab.setBounds(12+ wx...icon = new ImageIcon("01.png"); wolf_lab.setIcon(icon); } if
header = new ImageIcon(headerURL); // 头部 public static URL upURL = Data.class.getResource("/...up = new ImageIcon(upURL); public static ImageIcon down = new ImageIcon(downURL); public static...ImageIcon left = new ImageIcon(leftURL); public static ImageIcon right = new ImageIcon(rightURL)...body = new ImageIcon(bodyURL); //食物 public static URL foodURL = Data.class.getResource("/static.../body.png"); public static ImageIcon food = new ImageIcon(foodURL); } 4.
, height, null); //读取水印 Image temp1 = ImageIO.read(waterFile1); ImageIcon...imageIcon1 = new ImageIcon(temp1); watermarkImage1 = imageIcon1.getImage();...= waterFile2) { Image temp2 = ImageIO.read(waterFile2); ImageIcon imageIcon2...= new ImageIcon(temp2); watermarkImage2 = imageIcon2.getImage(); }
setPressedIcon(Icon) //改变按钮按下去时的样子 setSelectedIcon(Icon) //改变按钮被选中的样子 Icon是一个接口 找实现Icon的类ImageIcon...ImageIcon的构造方法: ImageIcon(Image) ImageIcon(String) ImageIcon(URL)
ia = new ImageIcon("D:\\S2\\丹哥\\API_07\\images\\a3.gif"); JLabel jla = new JLabel(ia); // 第一张图 //...ImageIcon ib = new ImageIcon("D:\\S2\\丹哥\\API_07\\images\3.gif"); JLabel jlb = new JLabel(ia); //...第一张图 // ImageIcon ic = new ImageIcon("D:\\S2\\丹哥\\API_07\\images\3.gif"); JLabel jlc = new JLabel(ia...Auto-generated method stub Random ran = new Random(); int i = ran.nextInt(4)+1; //创建图片 ImageIcon...ii = new ImageIcon("D:\\S2\\丹哥\\API_07\\images\\a" + i + ".gif"); jl.setIcon(ii); } public static
class Mpanel extends JPanel implements KeyListener, ActionListener { //定义所需要的图片元素 //标题 ImageIcon...title; //蛇的身体部位 ImageIcon body; //蛇向上方向的头 ImageIcon up; //蛇向下方向的头 ImageIcon...down; //蛇向左方向的头 ImageIcon left; //蛇向右方向的头 ImageIcon right; //食物元素 ImageIcon food...getClass().getClassLoader().getResourceAsStream("com/company/img/body.png"); body = new ImageIcon...getClass().getClassLoader().getResourceAsStream("com/company/img/down.png"); down = new ImageIcon
import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.ImageIcon...field_2.setBounds(130, 50,200, 30); //用来获取源文件(要切割的文件) button_1= new JButton("选择",new ImageIcon...button_1.addActionListener(listener); //用来获取目标文件夹(切割后存放发地点) button_2= new JButton("选择",new ImageIcon....setBounds(350, 50, 80, 30); // 下部面板 // 切割文件 button_Split = new JButton("切割",new ImageIcon...button_Split.setBounds(80, 100, 130, 30); // 打开目标文件夹 button_open = new JButton("打开目标文件夹",new ImageIcon
new JMenu("菜单"); 26 submenu = new JMenu("软件项目"); 27 item1 = new JMenuItem("java话题", new ImageIcon...("a.gif")); 28 item2 = new JMenuItem("动画话题", new ImageIcon("b.gif")); 29 item1.setAccelerator...("d.gif"))); 36 submenu.add(new JMenuItem("农场信息系统" , new ImageIcon("e.gif"))); 37 myBar.add...("a.gif")); //单一的条目 30 item2 = new JMenuItem("动画话题", new ImageIcon("b.gif")); 31...("c.gif"))); 39 submenu.add(new JMenuItem("农场信息系统", new ImageIcon("d.gif"))); 40 41
);//上 public static ImageIcon up=new ImageIcon(upURL); public static URL downURL=Data.class.getResource...("/static/x.png");//下 public static ImageIcon down=new ImageIcon(downURL); public static URL...leftURL=Data.class.getResource("/static/l.png");//左 public static ImageIcon left=new ImageIcon(leftURL...");//身体 public static ImageIcon body=new ImageIcon(bodyURL); public static URL foodURL=Data.class.getResource...("/static/food.png");//食物 public static ImageIcon food=new ImageIcon(foodURL); } 画板(功能实现)类: 这里面又涉及到了一个不是
java.util.MissingResourceException ; import java.util.ResourceBundle; import javax.swing.ImageIcon...this.setResizable(false); button_split = new JButton(" 文 件 切 割",new ImageIcon...button_split.addActionListener(listener); button_merge = new JButton(" 文 件 合 并",new ImageIcon...png"))); button_merge.addActionListener(listener); button_help = new JButton("帮 助",new ImageIcon...help.png"))); button_help.addActionListener(listener); button_about = new JButton("关 于",new ImageIcon
icon = new ImageIcon("off.png"); icon.setImage(icon.getImage().getScaledInstance(50, 50, 0))...image1 = new ImageIcon("star1.png"); g.drawImage(image1.getImage(), x - 3, y - 25, 28, 26..., null); } else { ImageIcon image1 = new ImageIcon("star2.png"); g.drawImage...icon = new ImageIcon("on.png"); icon.setImage(icon.getImage().getScaledInstance(50,...icon = new ImageIcon("off.png"); icon.setImage(icon.getImage().getScaledInstance(50,
} } class Demo{ public static void main(String[] args){ ImagePanel panel=new ImagePanel(new ImageIcon...image){ setSize(image.getWidth(null),image.getHeight(null));//方便测试透明的效果 setIcon(new ImageIcon...(image),null); } JButtonDemo(String image,String text){ this(new ImageIcon(image)...,text); } JButtonDemo(ImageIcon icon,String text){ setSize(icon.getImage().getWidth...) 2.鼠标滚动外观——setRolloverIcon(ImageIcon) 3.选中外观——setSelectedIcon(ImageIcon) …..
icon_state[] = new ImageIcon[2];//灯灭、灯亮的图片 2.在LightGame类的构造函数设置组件的属性 代码如下所示: icon_state[0] = new ImageIcon...("image//light_off.png");//灯灭图片 icon_state[1] = new ImageIcon("image//light_on.png");//灯亮图片...icon_menu[] = new ImageIcon[]{ new ImageIcon("image//icon008.png"), new ImageIcon("image...//icon007.png"), new ImageIcon("image//icon005.png"), new ImageIcon("image//icon020.png..."), new ImageIcon("image//icon034.png"), new ImageIcon("image//icon052.png"), }; 以上代码是创建
header = new ImageIcon(headerURL); public static URL downURL = Data.class.getResource("/statics...up = new ImageIcon(upURL); public static ImageIcon down = new ImageIcon(downURL); public static...ImageIcon left = new ImageIcon(leftURL); public static ImageIcon right = new ImageIcon(rightURL)...body = new ImageIcon(bodyURL); public static URL foodURL = Data.class.getResource("/statics/food.png..."); public static ImageIcon food = new ImageIcon(foodURL); } 4.
image1 = new ImageIcon("edit_pass1.png"); ImageIcon image2 = new ImageIcon("edit_pass2.png");...(tabbedPane, label_result,"图书管理系统-密码修改", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon...(tabbedPane, label_result,"图书管理系统-密码修改", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon...(tabbedPane, label_result,"图书管理系统-密码修改", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon...(tabbedPane, label_result,"图书管理系统-密码修改", JOptionPane.INFORMATION_MESSAGE,JOptionPane.OK_OPTION, new ImageIcon
com.swing; import java.awt.Container; import java.net.URL; import javax.swing.Icon; import javax.swing.ImageIcon...* Swing利用javax.swing.ImageIcon类根据现有的图片创建图标 * ImageIcon类实现了Icon接口,同时Java支持多种图片格式 * * 2:ImageIcon类有多个构造方法...* * 第一创建一个通用的ImageIcon对象,当真正需要设置图片时再使用ImageIcon对象 * 调用setImage(Image image)方法来操作 * 第二直接从图片源创建图表...imageButton.jpg,这个路径是相对于MyImageIcon类文件的 //所以可将imageButton.jpg图片放在和此类同一个文件夹下面 Icon icon=new ImageIcon
领取专属 10元无门槛券
手把手带您无忧上云