1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| package project;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Train extends JPanel{
private BufferedImage image;
public Train()
{this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
image=ImageIO.read(getClass().getResourceAsStream("/train.jpg"));
}
catch(IOException e)
{e.printStackTrace();
}
repaint();
}
private void setDefaultCloseOperation(int exitOnClose) {
// TODO Auto-generated method stub
}
public void paint(Graphics g)
{boolean drawImage = g.drawImage(image, 100, 100, null, null);
}
public static void main(String[] args) {
Train t=new Train();
}
} |
Partager