当前位置: 技术问答>java相关
java image
来源: 互联网 发布时间:2017-04-01
本文导语: 下面是一个练习,想显示一幅图象,但是不行,不知道什么原因,请高人指点! import java.awt.*; import javax.swing.*; public class Scale extends JFrame { Image image; Insets insets; public Scale(String filename) { super(filename); ...
下面是一个练习,想显示一幅图象,但是不行,不知道什么原因,请高人指点!
import java.awt.*;
import javax.swing.*;
public class Scale extends JFrame {
Image image;
Insets insets;
public Scale(String filename) {
super(filename);
//ImageIcon icon = new ImageIcon(filename);
//image = icon.getImage();
image = getToolkit().getImage(filename);
}
public void paint(Graphics g) {
super.paint(g);
if (insets == null) {
insets = getInsets();
}
g.drawImage(image, insets.left, insets.top, this);
}
public static void main(String args[]) {
if (args.length >0) {
Scale f = new Scale(args[0]);
f.setSize(400,400);
f.show();
} else {
System.out.println("Please specify a image file...");
}
}
}
import java.awt.*;
import javax.swing.*;
public class Scale extends JFrame {
Image image;
Insets insets;
public Scale(String filename) {
super(filename);
//ImageIcon icon = new ImageIcon(filename);
//image = icon.getImage();
image = getToolkit().getImage(filename);
}
public void paint(Graphics g) {
super.paint(g);
if (insets == null) {
insets = getInsets();
}
g.drawImage(image, insets.left, insets.top, this);
}
public static void main(String args[]) {
if (args.length >0) {
Scale f = new Scale(args[0]);
f.setSize(400,400);
f.show();
} else {
System.out.println("Please specify a image file...");
}
}
}
|
你的代码没有问题,
你遇见的问题和现象是什么???
你遇见的问题和现象是什么???
|
楼上很对