- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Java GUI 中显示图像文件 src/happyFace.gif 时遇到问题。目标是显示一张笑脸图像,该图像似乎以一定角度滑过程序窗口,并从窗口边缘弹起。
我认为我的问题在于 src/ReboundPanel.java 中的图像变量(类型 ImageIcon),因为 ImageIcon 类可能与 future 的 swing 版本不兼容(根据 Oracle 的文档: https://docs.oracle.com/javase/7/docs/api/javax/swing/ImageIcon.html )。如果这是真的,我认为 Swing 库可能无法支持 ImageIcon 类。我不知道如何检查我的 Swing 库。
src/happyFace.gif
我的输出窗口
src/Rebound.java:
//********************************************************************
// Rebound.java Java Foundations
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Rebound{
//-----------------------------------------------------------------
// Displays the main frame of the program.
//-----------------------------------------------------------------
public static void main (String[] args){
JFrame frame = new JFrame ("Rebound");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new ReboundPanel());
frame.pack();
frame.setVisible(true);
}
}
src/ReboundPanel.java:
//********************************************************************
// ReboundPanel.java Java Foundations
//
// Represents the primary panel for the Rebound program.
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ReboundPanel extends JPanel{
private final int WIDTH = 300, HEIGHT = 100;
private final int DELAY = 20, IMAGE_SIZE = 35;
private ImageIcon image;
private Timer timer;
private int x, y, moveX, moveY;
//-----------------------------------------------------------------
// Sets up the panel, including the timer for the animation.
//-----------------------------------------------------------------
public ReboundPanel(){
timer = new Timer(DELAY, new ReboundListener());
image = new ImageIcon ("happyFace.gif");
x = 0;
y = 40;
moveX = moveY = 3;
setPreferredSize (new Dimension(WIDTH, HEIGHT));
setBackground (Color.black);
timer.start();
}
//-----------------------------------------------------------------
// Draws the image in the current location.
//-----------------------------------------------------------------
public void paintComponent (Graphics page){
super.paintComponent (page);
image.paintIcon (this, page, x, y);
}
//*****************************************************************
// Represents the action listener for the timer.
//*****************************************************************
private class ReboundListener implements ActionListener{
//-----------------------------------------------------------------
// Updates the position of the image and possibly the direction
// of movement whenever the timer fires an action event.
//-----------------------------------------------------------------
public void actionPerformed (ActionEvent event){
x += moveX;
y += moveY;
if (x <= 0 || x >= WIDTH-IMAGE_SIZE)
moveX = moveX * -1;
if (y <= 0 || y >= HEIGHT-IMAGE_SIZE)
moveY = moveY * -1;
repaint();
}
}
}
最佳答案
在ReboundPanel
类中,
更改image = new ImageIcon("happyFace.gif");
至 image = new ImageIcon("src/happyFace.gif");
请注意,这种解决方案只能用于测试目的。如 Andrew Thompson 中所述的评论,存储和加载图像的正确方法是使用 embedded resource .
关于java - 在 Java 中显示一张笑脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48021588/
我的用户发现的一个小不便是,如果他们使用诸如 >_> 之类的表情符号在括号的末尾(有点像这样:>_>)然后在处理过程中它会运行 htmlspecialchars() ,制作 >_>) -
我是 java 邮件轮询的新手,如果用户互相发送邮件,我会在其中创建一种对话应用程序,然后我会从他们的邮件中读取该邮件并将其作为对话中的新消息发布。 现在的问题是,如果有笑脸、内联或嵌入图像怎么办。例
假设我在网站上有一个文本字段。我如何以编程方式使用户能够编写字母“:)”,然后在编辑器中将这两个字符转换为实际的笑脸图片 (.gif)? 我有点卡住了,因为我不知道如何查看文本字段,以及如何在正确的位
我在清理推文时遇到问题。我有一个将推文保存在 csv 中的过程,然后我对数据进行 pandas 数据框。 x 是来 self 的数据框的一条推文: 'b\'RT @LBC:詹姆斯·奥布莱恩谈到杰弗里·
我正在为我在 Stylish 中使用的 facebook 制作样式表。但是我偶然发现了一些我觉得很困惑的东西。我正在尝试将聊天中的笑脸更改为我自己的笑脸图像。 Facebook smileys My
为什么 modernizer 会生成一张笑脸...... 它来自生成的内容 div。我似乎无法在新的空 HTML 文件上复制效果 更新 我觉得笑脸来自 @font-face {font-family:
这个问题在这里已经有了答案: Chrome is not displaying my emoji correctly (2 个回答) 9 个月前关闭。 我正在尝试为网站信使显示表情符号,除 Smili
如何发送在编辑文本中一起编写的文本和表情符号/图像(不是默认的表情符号、 Assets 文件夹中的图像)以发送消息和聊天,因为它出现在该编辑文本中。 p.s 我正在通过邮件或邮件正文发送这些图片。 我
为了重新发明每一个轮子,我们公司最近推出了我们自己定制的基于网络的电子邮件应用程序,我是该应用程序的主要设计者。 我注意到的一件事是,来自基于 MS Outlook 的电子邮件(从第三方发送)的笑脸显
我正在做一个简单的聊天应用程序,我想在编写消息时在 edittext 上显示笑脸。 我用它来识别哪些字符将通过 ImageSpan 由 Image 替换(仅当在 EditText 上插入笑脸字符时才会
我是一名优秀的程序员,十分优秀!