📄 loadimage.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoadImage extends JFrame implements Runnable
{
Thread splashThread=null;
private ImagePanel imagePanel; //绘制图像的面板
private JProgressBar progress;
KeyListenerDemo key;
public LoadImage()
{
super("getImage");
// 返回一个具有指定预定义类型的光标对象。
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
this.setBounds(150,150,400,400);
//获取内容面板
Container container = getContentPane();
key=new KeyListenerDemo();
progress=new JProgressBar(1,100);
//显示进度条进度文本
progress.setStringPainted(true);
//显示进度条边框
progress.setBorderPainted(true);
progress.setString("汉偌塔游戏加载中....");
progress.setBackground(Color.white);
//创建用于绘制图像的面板
imagePanel = new ImagePanel();
container.add(imagePanel, BorderLayout.CENTER);
container.add(progress, BorderLayout.SOUTH);
splashThread=new Thread(this);
splashThread.start();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run()
{
try
{//经过100毫秒,进度条值增加1
for(int i=0;i<10;i++)
{
Thread.sleep(100);
progress.setValue(progress.getValue()+1);
if(i==9)
{
this.setVisible(false);
key.setVisible(true);
}
}
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
LoadImage application = new LoadImage();
}
class ImagePanel extends JPanel
{
private ImageIcon images;
public ImagePanel()
{
super();
setBackground(Color.WHITE);
//载入图像
// images= new ImageIcon("boy01.png");
images= new ImageIcon("d412505582.jpg");
}
public void paintComponent(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
g2d.setColor(getBackground());
g2d.fillRect(0, 0, getWidth(), getHeight());
//绘制图像,坐标为屏幕中心
int x = (this.getWidth() - images.getIconWidth())/2;
int y = (this.getHeight() - images.getIconHeight())/2;
images.paintIcon(this, g, x, y);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -