public class ImagePanel extends JPanel { // private ImageIcon image = null; // public ImagePanel(ImageIcon image) { this.image = image; } // protected void paintComponent(Graphics g) { setOpaque(true); super.paintComponent(g); Dimension d = getSize(); for (int x = 0; x < d.width; x += image.getIconWidth()) { for (int y = 0; y < d.height; y += image.getIconHeight()) { g.drawImage(image.getImage(), x, y, null, null); } } }}
//
private ImageIcon image = null;
//
public ImagePanel(ImageIcon image) {
this.image = image;
} //
protected void paintComponent(Graphics g) {
setOpaque(true);
super.paintComponent(g); Dimension d = getSize();
for (int x = 0; x < d.width; x += image.getIconWidth()) {
for (int y = 0; y < d.height; y += image.getIconHeight()) {
g.drawImage(image.getImage(), x, y, null, null);
}
}
}}
主要就是一个g.drawImage();方法。其他的都没用。
具体用法去查api就行了。
主要就是一个g.drawImage();方法。其他的都没用。
具体用法去查api就行了。
----------说的真轻松啊
//
private Image image ;
//
ImagePanel(Image image) {
setOpaque(true); this.image = image;
} //
protected void paintComponent(Graphics g) {
super.paintComponent(g); g.drawImage(...自己查api..
}}