Name: Anonymous 2007-01-23 6:01
"Write an application 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."
This is what I have, but the book doesn't say how to tell a panel to change its size or allow its labels to rearrange as needed, it only showed that will happen to the primary panel and its components in a frame. Apologies for being a noob.
import java.awt.*;
import javax.swing.*;
public class Faces
{
public static void main (String[] args)
{
JFrame frame = new JFrame ("Sum Faces!!");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
ImageIcon face1 = new ImageIcon ("face1.jpg");
ImageIcon face2 = new ImageIcon ("face2.jpg");
ImageIcon face3 = new ImageIcon ("face3.jpg");
ImageIcon face4 = new ImageIcon ("face4.jpg");
JLabel label1 = new JLabel (face1);
JLabel label2 = new JLabel (face2);
JLabel label3 = new JLabel (face3);
JLabel label4 = new JLabel (face4);
JPanel subpanel1 = new JPanel();
subpanel1.setBackground (Color.white);
subpanel1.setPreferredSize (new Dimension(650, 220));
subpanel1.add (label1);
subpanel1.add (label2);
JPanel subpanel2 = new JPanel();
subpanel2.setBackground (Color.yellow);
subpanel2.add (label3);
subpanel2.add (label4);
JPanel primary = new JPanel();
primary.setBackground (Color.black);
primary.add (subpanel1);
primary.add (subpanel2);
frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);
}
}
This is what I have, but the book doesn't say how to tell a panel to change its size or allow its labels to rearrange as needed, it only showed that will happen to the primary panel and its components in a frame. Apologies for being a noob.
import java.awt.*;
import javax.swing.*;
public class Faces
{
public static void main (String[] args)
{
JFrame frame = new JFrame ("Sum Faces!!");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
ImageIcon face1 = new ImageIcon ("face1.jpg");
ImageIcon face2 = new ImageIcon ("face2.jpg");
ImageIcon face3 = new ImageIcon ("face3.jpg");
ImageIcon face4 = new ImageIcon ("face4.jpg");
JLabel label1 = new JLabel (face1);
JLabel label2 = new JLabel (face2);
JLabel label3 = new JLabel (face3);
JLabel label4 = new JLabel (face4);
JPanel subpanel1 = new JPanel();
subpanel1.setBackground (Color.white);
subpanel1.setPreferredSize (new Dimension(650, 220));
subpanel1.add (label1);
subpanel1.add (label2);
JPanel subpanel2 = new JPanel();
subpanel2.setBackground (Color.yellow);
subpanel2.add (label3);
subpanel2.add (label4);
JPanel primary = new JPanel();
primary.setBackground (Color.black);
primary.add (subpanel1);
primary.add (subpanel2);
frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);
}
}