import java.awt.*; // for ImageIcon import javax.swing.*; // for JFrame, JPanel, JLabel public class Ch12_5b // create a GUI that displays 4 images in a 2x2 grid { public static void main(String[] args) { JFrame frame=new JFrame("Exercise12_1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400,400); // size may need to be adjusted based on image sizes JPanel p1=new JPanel(new GridLayout(2,2)); ImageIcon i1=new ImageIcon("rams.gif"); // create 4 ImageIcons, one each for the files ImageIcon i2=new ImageIcon("bengals.gif"); // note: only types of files that can be used as images are jpg, gif and png ImageIcon i3=new ImageIcon("flag.gif"); // if files are not in the same directory, include path in the filename ImageIcon i4=new ImageIcon("nku.gif"); p1.add(new JLabel(i1)); // add the ImageIcons to the JLabels and the JLabels to the JPanel p1.add(new JLabel(i2)); p1.add(new JLabel(i3)); p1.add(new JLabel(i4)); frame.add(p1); // add the JPanel to this JFrame and make it visible frame.setVisible(true); } }