Tag: imageicon

Eclipse中的Java:我在哪里把文件放在我想用getResource加载的文件系统上? (例如ImageIcon的图像)

我知道该文件需要在getClass()。getResource(文件名)可以find它,但我不知道在哪里。 我对将文件放在文件系统本身的位置以及如何使用Eclipse的function来设置资源感兴趣。

在do-while循环中更新定时器上的JButton

我有一些麻烦得到一个JButton重复更新(使用一个计时器)在一个do-while循环。 我正在做一个简单的游戏,在一个10 * 10的瓦片对象的网格上玩,这个网格对应着一个有100个button的JButton arrayList。 这部分程序处理简单的寻路(即如果我点击字符,然后是一个空的瓷砖,angular色将通过每个瓷砖到达目的地)。 每个步骤之间有一个延迟,用户可以看到angular色的进度。 在目前的情况下,运动是正确的,但JButton只是在字符到达目的地时才更新,而不是中间步骤。 public void move(int terrainTile) { int currentPosition = actorList.get(selectedActor).getPosition(); int movementValue = 0; int destination = terrainTile; int destinationX = destination / 10; int destinationY = destination % 10; do { currentPosition = actorList.get(selectedActor).getPosition(); // Gets PC's current position (before move) System.out.println("Old position is " + currentPosition); […]

弹簧行为模拟

基本上,我想模拟绘画图像上的弹簧行为。 我想让它通过几次迭代运行(比如固定在一个弹簧上)。 我在网上find的所有例子都会导致这个类 – FloatSpring.java 它应该提供所需的计算来将点A移动到点B,并使用类似弹簧的效果,这取决于各种FloatSpring类的设置。 问题是,我没有find一个明确的例子,如何正确使用它。 我做了这个小例子来testingFloatSpring : public static void main ( String[] args ) { // Some image to bounce final ImageIcon icon = new ImageIcon ( WebProgressOverlayExample.class.getResource ( "icons/ava1.jpg" ) ); // Component to paint image on JComponent spring = new JComponent () { // Zoom value (1f = 100% = […]

Swing中使用的框架图标的大小

我们可以使用一个列表来初始化使用Window.setIconImages(List<? extends Image>)的窗口图标。 在JFrame通常使用的不同大小的图标是什么? 码 此代码将64个不同大小的图像(从16×16,增加2)变成列表的图标。 import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; public class FrameIconList { public static BufferedImage getImage(int size, Color color) { BufferedImage i = new BufferedImage( size, size, BufferedImage.TYPE_INT_RGB); Graphics2D g = i.createGraphics(); g.setColor(color); g.fillRect(0, 0, size, size); g.setColor(Color.BLACK); int off = (size>17 ? 3 : […]

JLabel图像数组

我试图加载相同的jlabel存储的图像两次到一个网格布局面板,但不是创build图像的两个实例,图像只显示一次,然后移动。 如何将pieces数组中的相同JLabel位置存储到boardLabels数组中的多个JLabel中。 谢谢 :) public static JPanel boardPanel = new JPanel(new GridLayout(4, 0)); public static JLabel pieces[] = new JLabel[2]; private static JLabel[] boardLabels = new JLabel[4]; public MainFrame() { pieces[0] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "http://img.dovov.compiece1.png")); pieces[1] = new JLabel(new ImageIcon(System.getProperty("user.dir") + "http://img.dovov.compiece2.png")); this.add(boardPanel); displayGUIboard(); } public static void displayGUIboard() { //ERROR – the […]

Java Swing:显示来自Jar内的图像

从eclipse运行Java应用程序时,我的ImageIcon显示得很好。 但创build一个jar后,图像的path显然是搞砸了。 有没有办法在运行时从jar中提取图像,然后我可以打开它? 或者,有没有更好的方法来做到这一点? 如果可能,我想分发一个jar文件。

自动缩放ImageIcon以标签大小

在我的JFrame上,我使用下面的代码在面板上显示图像: ImageIcon img= new ImageIcon("res.png"); jLabel.setIcon(img); 我想“自动调整”标签中的图片。 事实上,有时图像尺寸只有几个像素,有时甚至更多。 有没有办法设置标签的大小,然后自动大小的标签中的图像?