首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏緣來來來

    Java中ImageIcon的路径问题

    一、遇到的问题 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等格式。

    3.4K10发布于 2020-01-02
  • 来自专栏日志随记

    Java实现扫雷小游戏一

    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(".

    1.6K50编辑于 2022-05-27
  • 来自专栏全栈程序员必看

    JAVA贪吃蛇代码(带注释)

    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() {

    1.4K20编辑于 2022-09-01
  • 来自专栏Java技术分享圈

    喜洋洋大战灰太狼

    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

    84610发布于 2021-11-30
  • 来自专栏兮动人的博客

    Java之实现贪吃蛇小游戏

    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.

    99520发布于 2021-06-11
  • 来自专栏全栈程序员必看

    Graphics2D绘制多图片水印方法

    , 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(); }

    66710编辑于 2022-07-28
  • 来自专栏钟绍威的专栏

    怎么改变按钮的图标

    setPressedIcon(Icon) //改变按钮按下去时的样子 setSelectedIcon(Icon) //改变按钮被选中的样子 Icon是一个接口 找实现Icon的类ImageIcon ImageIcon的构造方法: ImageIcon(Image) ImageIcon(String) ImageIcon(URL)

    3K100发布于 2018-02-05
  • 来自专栏ml

    初学java之菜单条,菜单,菜单项的设置

    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

    2.8K30发布于 2018-03-22
  • 来自专栏全栈程序员必看

    java实现贪吃蛇小游戏(源码+注释)

    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

    1.3K10编辑于 2022-09-01
  • 来自专栏Java技术分享圈

    喜洋洋大战灰太狼(大结局)

    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

    65410发布于 2021-11-30
  • 来自专栏自动化测试工具

    什么是线程以及线程的使用+示例

    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

    85510编辑于 2022-11-18
  • 来自专栏明明如月的技术专栏

    文件切割合并器 2 切割类 Split

    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

    1.2K20发布于 2021-08-27
  • 来自专栏明明如月的技术专栏

    图书管理系统代码 9 EditpassW (…

    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

    79920发布于 2021-08-27
  • 来自专栏技术集锦

    【Python | Java】代码绘制圣诞树

    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,

    2.2K20编辑于 2022-06-03
  • 来自专栏Java进阶学习交流

    手把手带你用Java实现点灯游戏(上篇)

    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"), }; 以上代码是创建

    1.3K31发布于 2021-01-22
  • 来自专栏全栈程序员必看

    JAVA实现贪吃蛇游戏

    );//上 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); } 画板(功能实现)类: 这里面又涉及到了一个不是

    98430编辑于 2022-06-25
  • 来自专栏明明如月的技术专栏

    文件切割合并器  1 主类  SplitAnd…

    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

    49420发布于 2021-08-27
  • 来自专栏全栈开发工程师

    【Java GUI编程】003-Swing学习笔记(一):窗口、弹窗、标签、面板

    true); jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } } 运行结果: 三、Icon和ImageIcon width; } @Override public int getIconHeight() { return height; } } 运行结果: 3、ImageIcon public TestImageIcon() throws HeadlessException { //获取图片地址 JLabel label = new JLabel("ImageIcon "); URL url = TestImageIcon.class.getResource("tx.jpg"); ImageIcon imageIcon = new ImageIcon (url); label.setIcon(imageIcon); label.setHorizontalAlignment(SwingConstants.CENTER);

    53010编辑于 2025-01-06
  • 来自专栏钟绍威的专栏

    创建被图像填充的组件解释几处做法解释几点

    } } 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) …..

    1.7K90发布于 2018-02-05
  • 来自专栏人工智能与演化计算成长与进阶

    java Swing GUI 入门-图片和控件可视化

    ,要不然太大了把其他的内容都遮住了 private void createUIComponents() { logoLabel = new JLabel(); ImageIcon logoIcon = new ImageIcon(new ImageIcon("image/a.png").getImage().getScaledInstance(300, 250, Image.SCALE_SMOOTH frame.setVisible(true); } private void createUIComponents() { logoLabel = new JLabel(); ImageIcon logoIcon = new ImageIcon(new ImageIcon("image/a.png").getImage().getScaledInstance(300, 250, Image.SCALE_SMOOTH

    1.4K10发布于 2021-01-04
领券