关于JAVA中Graphice里的drawimage方法的一个问题?
importjava.awt.Graphics;importjava.awt.Image;importjava.awt.Toolkit;importjavax.swing...
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
class MyGraphics extends JPanel {
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
Toolkit tool = this.getToolkit();
Image image = tool.getImage("tank.jpg");
g.drawImage(image, 10, 10, image.getWidth(this), image.getHeight(this),
this);
}
}
public class CTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.add(new MyGraphics());
frame.setVisible(true);
}
}
这是测试代码,tank这张图片我放在了这个项目的src文件夹里,运行之后只显示出一个窗口,显示不出图片来,这是为什么?(图片大小1024*552,75.3KB大) 展开
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
class MyGraphics extends JPanel {
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
Toolkit tool = this.getToolkit();
Image image = tool.getImage("tank.jpg");
g.drawImage(image, 10, 10, image.getWidth(this), image.getHeight(this),
this);
}
}
public class CTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.add(new MyGraphics());
frame.setVisible(true);
}
}
这是测试代码,tank这张图片我放在了这个项目的src文件夹里,运行之后只显示出一个窗口,显示不出图片来,这是为什么?(图片大小1024*552,75.3KB大) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询