import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
class ImageImplement extends JPanel {
private Image img;
private int leftPos =0;
public ImageImplement(Image img) {
this.img = img;
Dimension size = new Dimension(0, 0);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics gr) {
//
// VB.NET Code
// Dim img As New Bitmap(Application.StartupPath & "\img\char.png")
// frames(x) = New Bitmap(32, 48)
// Dim gr As Graphics = Graphics.FromImage(frames(x))
// gr.DrawImage(img, 0, 0, New Rectangle(leftPos, Int(x / 4) * 64, 70, 70), GraphicsUnit.Pixel) <--VB.NET
// VB.NET
// int frameX = (0 % columns) * width;
// int frameY = (0/ columns) * height;
//gr.drawImage(img, 0, 0, leftPos, ((int) x / 4 ) * 64, 70, 70, null);
// gr.drawImage(img, 0, 0, 70, 70, this);
gr.drawImage(img, 0, 0, 40, 70, 50, 0, 70, 70, null); //<--I am currently experimenting on this one
}
// public void paint(Graphics g) {
// super.paint(g);
//
// Graphics2D g2d = (Graphics2D)g;
// g2d.drawImage(img, 0, 0, 32, 78, this);
//
// //Toolkit.getDefaultToolkit().sync();
// g.dispose();
// }
}
public class MainWIn extends JFrame
{
public static void main(String args[])
{
new MainWIn().start();
}
public void start()
{
ImageImplement panel = new ImageImplement(new ImageIcon("D:\\char.png").getImage());
add(panel);
setVisible(true);
setSize(400,400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}