SetImageIconTest.java
| 1 |
package test; |
|---|---|
| 2 |
|
| 3 |
import java.awt.Color; |
| 4 |
import java.awt.Graphics; |
| 5 |
import java.awt.Graphics2D; |
| 6 |
import java.io.File; |
| 7 |
import java.io.IOException; |
| 8 |
|
| 9 |
import javax.imageio.ImageIO; |
| 10 |
import javax.swing.JComponent; |
| 11 |
import javax.swing.JFrame; |
| 12 |
import javax.swing.SwingUtilities; |
| 13 |
|
| 14 |
public class SetImageIconTest |
| 15 |
{
|
| 16 |
|
| 17 |
public static void main(String[] args) |
| 18 |
{
|
| 19 |
SwingUtilities.invokeLater(new Runnable() |
| 20 |
{
|
| 21 |
public void run() |
| 22 |
{
|
| 23 |
final JFrame frame = new JFrame("Test setIconImage"); |
| 24 |
frame.setSize(800, 600); |
| 25 |
frame.setLocation(150, 150); |
| 26 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
| 27 |
//frame.setUndecorated(true);
|
| 28 |
final boolean[] changeIcon = new boolean[] { true }; |
| 29 |
frame.setContentPane(new JComponent() |
| 30 |
{
|
| 31 |
public void paint(Graphics g) |
| 32 |
{
|
| 33 |
if (changeIcon[0]) |
| 34 |
{
|
| 35 |
frame.setVisible(false);
|
| 36 |
new Thread(new Runnable() |
| 37 |
{
|
| 38 |
@Override
|
| 39 |
public void run() |
| 40 |
{
|
| 41 |
changeIcon[0] = false; |
| 42 |
try
|
| 43 |
{
|
| 44 |
frame.setIconImage(ImageIO.read(new File("./gclogo.ico"))); |
| 45 |
} |
| 46 |
catch (IOException e) |
| 47 |
{
|
| 48 |
e.printStackTrace(); |
| 49 |
} |
| 50 |
SwingUtilities.invokeLater(new Runnable() |
| 51 |
{
|
| 52 |
|
| 53 |
@Override
|
| 54 |
public void run() |
| 55 |
{
|
| 56 |
frame.setVisible(true);
|
| 57 |
//((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
|
| 58 |
} |
| 59 |
}); |
| 60 |
} |
| 61 |
}).start(); |
| 62 |
} |
| 63 |
Graphics2D g2 = (Graphics2D) g; |
| 64 |
g2.setBackground(Color.white);
|
| 65 |
g2.clearRect(0, 0, 800, 600); |
| 66 |
} |
| 67 |
}); |
| 68 |
frame.setVisible(true);
|
| 69 |
|
| 70 |
} |
| 71 |
}); |
| 72 |
|
| 73 |
} |
| 74 |
} |