import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class ImageViewer{
public static void main(String[]args){
JFrame window = createWindow();
ImageIcon icon = createIcon("Desert.jpg");
JLabel label = addIconToGraphicalComponent(icon);
addGraphicalComponentToWindow(window, label);
addMenuToWindow(window);
}
public static JFrame createWindow(){
JFrame window = new JFrame("Image Viewer");
window.setSize(600,400);
window.setDefaultCloseOperation(window.EXIT_ON_CLOSE);
window.setResizable(false);
window.setVisible(true);
return window;
}
public static ImageIcon createIcon(String fileName){
ImageIcon icon = new ImageIcon(fileName);
return icon;
}
public static JLabel addIconToGraphicalComponent(ImageIcon icon){
JLabel label = new JLabel(icon);
return label;
}
public static void addGraphicalComponentToWindow(JFrame window, JLabel label){
Container windowContentPane = window.getContentPane();
windowContentPane.add(label);
}
public static void addMenuToWindow(JFrame window){
JMenuBar windowMenuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open Image");
JMenuItem exitItem = new JMenuItem("Exit Application");
fileMenu.add(openItem);
fileMenu.add(exitItem);
windowMenuBar.add(fileMenu);
window.setJMenuBar(windowMenuBar);
}
}