{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

GroupPhoto - Make the frame fit around its contents If...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab10; p import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; i /** * This class displays a bunch of portraits in a scrollable window. */ public class GroupPhoto extends JFrame { p public GroupPhoto(ArrayList<Portrait> portraits) { super("Our Family"); // Create a gridded panel having enough spots for every portrait. // Portraits are arranged in a square. JPanel panel = new JPanel(); int root = (int) Math.ceil(Math.sqrt(portraits.size())); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); for (Portrait p : portraits) { constraints.gridx = (constraints.gridx + 1) % root; panel.add(p, constraints); } // We'll someday have enough portraits that our window won't be big // enough, so let's give it scrollbars. JScrollPane scroller = new JScrollPane(panel); add(scroller);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Make the frame fit around its contents. If you're on a netbook, // you might want to shrink the height, the second argument. setSize(800, 800); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String args) { ArrayList<Portrait> portraits = new ArrayList<Portrait>(); portraits.add(new Portrait(0.2)); // Replace these constructor calls with calls to constructors // of code you pull off of WebCT. portraits.add(new Portrait10AB()); // portraits.add(new Portrait10AB(0.21)); // portraits.add(new Portrait(0.22)); // portraits.add(new Portrait(0.23)); // portraits.add(new Portrait(0.24)); // portraits.add(new Portrait(0.25)); // portraits.add(new Portrait(0.26)); // portraits.add(new Portrait(0.27)); // portraits.add(new Portrait(0.28)); // portraits.add(new Portrait(0.29)); // portraits.add(new Portrait(0.3)); new GroupPhoto(portraits); } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

GroupPhoto - Make the frame fit around its contents If...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online