简体   繁体   English

Java 2D游戏-我不懂一些代码

[英]Java 2D Game - I Don't Understand Some Code

BufferedImage image;
image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));

I am currently making a 2D Java Game, as per an exercise in a course I am taking; 我目前正在按照自己正在学习的课程中的一个练习制作2D Java游戏; however, there are a couple of things I do not understand here. 但是,有些事情我在这里不明白。 The first thing I am not too sure about is: 我不太确定的第一件事是:

SpriteSheet.class

I have never seen .class ever be used before. 我从未见过.class曾经被使用过。 What exactly is it? 到底是什么 Furthermore, why does just putting in path in the getResourceAsStream method work. 此外,为什么只将路径放入getResourceAsStream方法中即可。 Is it because I have the SpriteSheet in a res folder, which is in the program's build path. 是因为我将SpriteSheet放在res文件夹中,该文件夹位于程序的构建路径中。

Thank you for the help! 感谢您的帮助!

.class refers to the Class object for a given class. .class指给定类的Class对象。

for example, Integer.class will refer to the Class object for java.lang.Integer . 例如, Integer.class将引用java.lang.IntegerClass对象。

getResourceAsStream() will return an InputStream pointing to a file in the current classpath. getResourceAsStream()将返回一个InputStream指向当前类路径中的文件。

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

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