- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在为我的应用程序制作启动画面。它只是由 Graphics2D 绘制的静态 BufferedImage,位于 JFrame 内部,没有任何装饰。我的问题是:窗口有时绘制不正确,这意味着它并不总是包含我的图像,有时它只是灰色的。我已经尝试在第二个线程中创建启动画面,但没有帮助。我可以在每一行调用 splashScreen.repaint()
,但这是无稽之谈......这是我的代码:
package SeriousSteve.MapEditor;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
/**
* Simple splash screen, contains only the image.
*
* @author m4tx3
*/
public class SplashScreen extends JFrame {
private BufferedImage image;
/**
* Constructor. Creates a window with splash screen, loads an image at the
* URL specified in imageURL, and finally displays this image.
*
* @param imageURL URL to the image that you want to put on the splash
* screen.
*/
public SplashScreen() {
super("Splash screen");
}
public void createSplashScreen(final URL imageURL) {
try {
image = ImageIO.read(imageURL);
} catch (IOException ex) {
Logger.getLogger(SplashScreen.class.getName()).
log(Level.SEVERE, null, ex);
}
setUndecorated(true);
setSize(image.getWidth(), image.getHeight());
setLocationRelativeTo(null);
setVisible(true);
createGraphics();
repaint();
}
/**
* Creates a graphics context and draws a splash screen.
*/
private void createGraphics() {
Graphics2D g = (Graphics2D) getGraphics();
g.drawImage(image, 0, 0, null);
}
/**
* Closes the splash screen and frees the memory taken by the image.
*
* Call this function when the loading is complete.
*/
public void close() {
setVisible(false);
image = null;
dispose();
}
}
和:
SplashScreen splashScreen = new SplashScreen();
splashScreen.createSplashScreen(getClass().getResource(
"Img/splash.png"));
顺便说一句,- 我正在创建自己的启动画面类,因为我在 1 个 jar 中有 2 个应用程序(游戏和 map 编辑器)...我只想在 map 编辑器中显示启动画面,所以我不能修改 list 文件。
问候
最佳答案
改用JLabel
。直接在框架上绘画是个坏主意。
看到这个,它每次都有效:
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* Simple splash screen, contains only the image.
*
* @author m4tx3
*/
public class SplashScreen extends JFrame {
/**
* Constructor. Creates a window with splash screen, loads an image at the URL specified in imageURL, and finally displays this image.
*
* @param imageURL
* URL to the image that you want to put on the splash screen.
*/
public SplashScreen() {
super("Splash screen");
}
public void createSplashScreen(final URL imageURL) {
JLabel splashLabel = new JLabel(new ImageIcon(imageURL));
add(splashLabel);
setSize(splashLabel.getPreferredSize());
setUndecorated(true);
setLocationRelativeTo(null);
setVisible(true);
repaint();
}
/**
* Closes the splash screen and frees the memory taken by the image.
*
* Call this function when the loading is complete.
*/
public void close() {
setVisible(false);
dispose();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
new SplashScreen().createSplashScreen(new URL(
"http://art.gnome.org/download/themes/splash_screens/1334/Splash-GnomeDarkSplashScreen.png"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
关于java - 由于没有重新粉刷,灰色启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10521192/
我有一个表,用于测量数据集中两个不同值的分布百分比(我有一个计数,替换为 Percentage )。我只想在仪表板中发布 85% 的值。这样做的步骤是什么? .现在,如果我过滤掉 NO 值, YES
我想平均N通过Type对于 Inst 的值 我的数据设置为: Type, Inst, N A, A1, 4 A, A1, 13 A, A1, 13 A, A2, 4 A, A3, 5 B, B1, 4
当我使用 Node 的 http2 库(仅支持 HTTPS,不支持 HTTP)进行开发时,当我在 Chrome 中打开 localhost 时,我会看到一个警告屏幕: Your connection
我想创建一个具有响应式布局的导航栏菜单。当网站显示在显示器上时,我想播放导航栏。当网站在手机上显示时,我会显示最终显示导航栏的菜单图标。 我该怎么做? 最佳答案 试试这个,在移动设备上,导航栏不仅会显
我聘请了一名程序员为我创建一个 iPhone 应用程序。该应用程序的目的是拍照并将其上传到服务器。我们想制作一个特殊用途的屏幕,以便在上传照片之前查看照片。这个专门开发的屏幕将具有至关重要的缩放功能。
我在 Tableau 上有一个我无法解决的简单问题。 我想显示一个图表,显示随时间变化的度量。我想将用户通过参数选择的一个客户端与未选择的所有其他客户端进行比较。该图将显示具有 2 种不同颜色的两条线
我使用 Python 脚本从 3 个不同的 RDS 执行一系列复杂查询,然后将数据导出到一个 CSV 文件中。我现在正在尝试找到一种方法,每周将使用这些数据的仪表板自动发布到 Tableau 服务器中
我在工作中使用 tableau 来处理各种数据类型,包括敏感的个人数据,这些数据只能以聚合格式共享。我试图找到一种方法来保护私有(private)信息,方法是在单元格值小于 5 时隐藏它。这样,当用户
我最近开始在网站上嵌入 Tableau 可视化效果,并遇到了在浏览器中直接使用 Control + P 打印它们的问题。大多数完全扭曲,如果有的话。我做了一些挖掘,发现这是一个已知问题: http:/
例如,此 URL 包含十几个项目:https://tableautest.domain.uk/t/CustomerSharing/view/projects 在每个项目中都有几个工作簿。每个工作簿中都
我正在研究如何使用 Tableau 连接到 Cloudera Hadoop。我提供服务器和端口详细信息并使用“Impala”进行连接。我能够成功连接,选择默认模式并选择所需的表。 在此之后,当我将维度
我正在尝试将 Tableau 工作表嵌入到我的 ReactJS 应用程序中。我有一个包含报告名称列表的菜单(在 react 中),当单击菜单项时,它会更新包含报告名称的状态。我决定使用 tableau
我有以下问题!我有一个这样的表: Data Source 我想创建一个可以获取 apl_id 的字段(我想这是一个字段),有一些我想要的 service_offered。 上表中的示例。如果我想要只有
我有一个航类延误数据电子表格,我正在处理一个显示每个机场总延误时间的工作表。我想过滤维度“机场”,即根据每个机场的起飞次数创建机场类别,“小型”、“中型”和“大型”,这是通过计算维度“航类号”计算得出
我想创建一个带有过滤器的表格,用于选择和比较事物: 假设我有一个变量 Var,包含值 A、B、C、D、E。我想要一个过滤器,以便用户可以选择 A B C D 之一,同时 E 始终被选中。这样选中的E和
我是一名优秀的程序员,十分优秀!