我实际上想加载图像但只打开小程序对话框并且没有发生错误但图像没有加载。代码在下面
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Ball extends JPanel{
Image image;
public Ball(){
super();
image = Toolkit.getDefaultToolkit().getImage("/D:\\lolololo\\tuto\\bin\\sa.jpg");
}
private Image getResource(String string) {
return image;
// TODO Auto-generated method stub
}
public void paintComponent(Graphics g){
// Draw our Image object.
g.drawImage(image,50,10,574,960, this); // at location 50,10
// 200 wide and high
}
public void main(String arg[]){
JFrame frame = new JFrame("ShowImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,500);
Ball panel = new Ball();
frame.setContentPane(panel);
frame.setVisible(true);
}
}