这是我的第一类
import javax.swing.JFrame;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
public class Fish extends JFrame{
private static Toolkit tk = Toolkit.getDefaultToolkit();
private static Image img;
static{img = tk.getImage(Fish.class.getClassLoader().getResource("images/1.jpg"));}
public Fish() {
this.setSize(440,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new CanvasPanel());
}
public void draw(Graphics g) {
g.drawImage(img,0,0,this);
}
}
然后我想在另一类(Main)中声明一个Fish类的对象,然图片在Main中绘制,那么我的Main类应该怎么写
类 绘制图片 对象
------解决方案--------------------
public static void main(String[] args) {
new Fish() ;
}