0% found this document useful (0 votes)
38 views2 pages

Display Image

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Display Image

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.awt.

Container;
import java.awt.EventQueue;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class DisplayImage extends JFrame {

public DisplayImage() {

initUI();
}

private void initUI() {

ImageIcon ii = loadImage();

JLabel label = new JLabel(ii);

createLayout(label);

setTitle("Image");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

private ImageIcon loadImage() {

ImageIcon ii = new ImageIcon("src/images/snake.jpg");


return ii;
}

private void createLayout(JComponent... arg) {

Container pane = getContentPane();


GroupLayout gl = new GroupLayout(pane);
pane.setLayout(gl);

gl.setAutoCreateContainerGaps(true);

gl.setHorizontalGroup(gl.createSequentialGroup()
.addComponent(arg[0])
);

gl.setVerticalGroup(gl.createParallelGroup()
.addComponent(arg[0])
);

pack();
}

public static void main(String[] args) {

EventQueue.invokeLater(() -> {
DisplayImage ex = new DisplayImage();
ex.setVisible(true);
});
}
}

You might also like