哪一種創建圖像的方法好一些?
1. Image image = java.awt.Toolkit.getDefaultToolkit.getImage(java.lang.String / java.net.URL);
使用這個方法,馬上返回,而圖像的加載是在后臺進行,即,并不能馬上得到圖像的數據
2. Image image = new ImageIcon(fileName / url).getImage();
直到圖像加載完后,才向下繼續運行
java.awt.Image
|__java.awt.image.BufferedImage
Graphics g = bufferedImage.getGraphics();
在g上畫圖
protected void javax.swing.JComponent.paintComponent(java.awt.Graphics g) {
super.paintComponent(g); // 保證實現雙緩沖
Graphics2D g2d = (Graphics2D)g2d;
}
如在另一個線程中加載圖像數據,然后調用panel.repaint(),使新加載的圖像顯示出來
不要去重寫paint方法與repaint