Set image in frame.....
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
class Test{
public static void main(String[] args) {
JFrame frame = new JFrame("Gym Management System");
frame.setSize(500, 410);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setSize(500, 410);
frame.add(panel);
ImageIcon ic = new ImageIcon("C:\\Users\\user\\Downloads\\Gym app.jpg");
ImageIcon resizeImage = resize(ic, 500, 410);
JLabel jimage = new JLabel(resizeImage);
panel.add(jimage);
frame.setVisible(true);
}
private static ImageIcon resize(ImageIcon im, int w, int h) {
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TRANSLUCENT);
Graphics2D gd = (Graphics2D) bi.createGraphics();
gd.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
gd.drawImage(im.getImage(), 0, 0, w, h, null);
gd.dispose();
return new ImageIcon(bi);
}
}

Comments
Post a Comment