I'm learning JavaSwing. I wanted to draw an Image on the frame, but I want the picture resolution drawn to be like 300*300. Here is my code for drawing an Image on the panel.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Picture
{
JFrame frame;
public static void main(String[] args)
{
Picture poo = new Picture();
poo.go();
}
private void go()
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
frame.getContentPane().add(new ImageOne());
}
class ImageOne extends JPanel
{
public void paintComponent(Graphics g)
{
Image img = new ImageIcon("image.jpg").getImage();
g.drawImage(img, 2, 2, this);
}
}
}
Can anyone tell me how to do this? I searched the net, but I could find explanations relating to BufferedImage, and I don't know how to use that.
Thanks in advance.