ImageIcon icon= new ImageIcon("a.gif");
JLabel jLabel1=new JLabel(icon);
jLabel1.setVisible(true);
card1.add(jLabel1);
Run Code Online (Sandbox Code Playgroud)
我是Java的新手,我在applet中的面板中添加图像时遇到了问题.我的图片位于同一个文件夹中.我的小程序可见而没有任何问题,但只显示图像.
我想知道是否可以在Java中分层ImageIcons.我将使用GIF图像,并将有一个ImageIcons网格代表我的JPane的"背景".
当某个条件成立时,我需要能够在另一个图像的顶部添加一个透明的图像.
此致,杰克亨特
好的,所以我从数据库中获取单个图像没有问题.我用它来把它作为ImageIcon一个JLabel;
while (rs.next()) {
images = rs.getString("path");
System.out.println(images + "\n");
System.out.println("TESTING - READING IMAGE");
BufferedImage img = ImageIO.read(new File(images));
System.out.println("img = " + images);
imagelabel = new JLabel(new ImageIcon(img));
imagelabel.setPreferredSize(new Dimension(200, 200));
imageselect.add(imagelabel);
Run Code Online (Sandbox Code Playgroud)
但是,我需要对多个图像执行此操作,并将每个图像分配JLabel给一个新JPanel的图像CardLayout.我知道我需要某种循环,寻找最佳方法的建议!
BufferedImage imgA = ImageIO.read(new File("lmkpackage/images/one.jpg"));
image1 = new JLabel(new ImageIcon(imgA));
image1.setPreferredSize(new Dimension(200, 200));
img1 = new JPanel();
img1.add(image1);
loadcard.add(img1,"1");
cl2.show(loadcard,"1");
BufferedImage imgB = ImageIO.read(new File("lmkpackage/images/two.jpg"));
image2 = new JLabel(new ImageIcon(imgB));
image2.setPreferredSize(new Dimension(200, 200));
img2 = new …Run Code Online (Sandbox Code Playgroud) 我正试图在图像处理方面做一个实验.基本上我有一个图像,由计时器不断更新,我在JLabel中显示该图像.
我的问题是JLabel没有刷新图像.
这是我的计时器代码:
Timer timer = new Timer(200, new ActionListener() {
public void actionPerformed(ActionEvent e) {
count++;
System.out.println("timer");
System.out.println(filename);
ImageIcon icon = new ImageIcon(filename);
label = new JLabel();
label.setIcon(icon);
label.setText(""+count);
panel = new JPanel();
panel.add(label);
frame.getContentPane().removeAll();
frame.getContentPane().add(panel);
frame.repaint();
frame.validate();
try{
FileWriter fstream;
fstream = new FileWriter(filename,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("text to append");
out.close();
}catch (Exception ex){
System.err.println("Error: " + ex.getMessage());
}
}
});
Run Code Online (Sandbox Code Playgroud)
其中filename是我的图像的路径.
显示图像但JLabel从不刷新我的图像.我测试了我的代码,如果我在两个不同的图像之间切换,它正在工作......
编辑:
每次创建最后一个图像并使用时间戳重命名时,我都会通过复制解决.
基本上,我想模拟绘制图像上的弹簧行为.我想让它通过几次迭代来上下缩放(就像在弹簧上修复一样).
我在网上找到的所有例子都导致了这个类 - FloatSpring.java
它应该提供所需的计算,将A点移动到B点,应用类似弹簧的效果,这取决于各种FloatSpring类设置.问题是我没有找到一个明确的例子如何正确使用它.
我做了这个小例子来测试FloatSpring:
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% = normal size)
float zoom = 1f;
{
// Basic spring settings
final FloatSpring fs = new FloatSpring ( 100 );
fs.setPosition ( zoom );
// Animation …Run Code Online (Sandbox Code Playgroud) 我让动画在Snake Clone Game中运行.但基于图片的问题是图像没有透明度(注意圆形图片的白色背景.编程方面,是否有一个修复,能够包括这些绘制图像的透明度?
这是包含我的代码和程序输出的图片.

PS在旁注中,我决定粘贴直接链接而不是IMG代码,因为我似乎无法在StackOverFlow上显示它.我在IMG代码的前面加了一个感叹号,但它没有用,所以这里是直接链接.
lblImage = new javax.swing.JLabel();
lblImage.setIcon(new javax.swing.ImageIcon("E:..path...png"));
Run Code Online (Sandbox Code Playgroud)
我添加了这样的文件.我知道在运行jar文件时它没有访问路径.帮助我如何将图像文件导入Netbeans中的Java项目.
我正在尝试创建一个左侧文本对齐且右侧图标对齐的JLabel,我尝试了以下代码:
_ip = new JLabel(ip);
_ip.setFont(boldFont);
_ip.setBounds(5, 0, 100, 50);
_ip.setIcon(images.ipBan);
_ip.setBorder(BorderFactory.createLineBorder(Color.black, 1));
_ip.setHorizontalTextPosition(SwingConstants.LEFT);
add(_ip);
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:

红色图像显示实际图像对齐,灰色图像显示我想要图像的位置.
如果我添加
_ip.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
Run Code Online (Sandbox Code Playgroud)
什么都没发生,如果我补充
_ip.setHorizontalAlignment(JLabel.RIGHT);
Run Code Online (Sandbox Code Playgroud)
图标右对齐,但文本右对齐,我希望它左对齐
有办法吗?
在我的应用程序中,我正在显示应用程序商店中的一些应用程序列表.
我想在我的应用程序中获取这些应用程序的图标图像.
我只是搜索但没有得到任何相关的帖子.
有没有办法得到它?Apple允许获得?请建议是否有任何方法.
谢谢您的帮助.
你好我是编程的新手,我们有一个项目.我们创建了一个简单的赛车游戏,背景动人,但我坚持我的代码,我不知道该怎么做.游戏开始时我需要一个移动的背景请有人帮助我.我在求T_T

这是我的代码:
public class Game extends JFrame implements KeyListener, ActionListener {
Random s = new Random();
int x = 0, y = 50, a = 0, b = 250, f = 900, a1 = 0, b2 = 350, a2 = 0, b3 = 150;
int Move;
int value;
JLabel spriteLabel1 = new JLabel(new ImageIcon("ss.gif"));
JLabel spriteLabel2 = new JLabel(new ImageIcon("ss.gif"));
JLabel spriteLabel3 = new JLabel(new ImageIcon("ss.gif"));
JLabel spriteLabel4 = new JLabel(new ImageIcon("ss.gif"));
JLabel background = new JLabel(new ImageIcon("geren.png"));
Timer T1 …Run Code Online (Sandbox Code Playgroud)