Please write in Java The complier I am using is Eclispe Writ
Please write in Java. The complier I am using is Eclispe
Write a program that displays a frame containing two panels. Each panel should contain two images (use four unique images – your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does.
Solution
import java.awt.*;
import javax.swing.*;
public class TwoPanels
{
public static void main(String[] args)
{
JFrame frame = new JFrame (\"Embedded Images\");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
ImageIcon iconOne = new ImageIcon (\"glove.jpg\");
ImageIcon iconTwo = new ImageIcon (\"cleats.jpg\");
ImageIcon iconThr = new ImageIcon (\"bat.jpg\");
ImageIcon iconFou = new ImageIcon (\"baseball.jpg\");
JLabel l1, l2, l3, l4;
l1 = new JLabel (\"\", iconOne, SwingConstants.CENTER);
l2 = new JLabel (\"\", iconTwo, SwingConstants.CENTER);
l3 = new JLabel (\"\", iconThr, SwingConstants.CENTER);
l4 = new JLabel (\"\", iconFou, SwingConstants.CENTER);
JPanel p1 = new JPanel();
p1.setBackground(Color.green);
p1.add(l1);
p1.add(l2);
JPanel p2 = new JPanel();
p2.setBackground(Color.green);
p2.add(l3);
p2.add(l4);
JPanel pmain = new JPanel();
pmain.setBackground(Color.blue);
pmain.add(p1);
pmain.add(p2);
frame.getContentPane().add(pmain);
frame.pack();
frame.setVisible(true);
}
}

