import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; public class main { public static void main(String[] args) throws Exception { List parts = new ArrayList(); for (int n = 1; n <= 4; n++) parts.add(new JButton("Yo " + n)); showPackedFrame("4 Choices", vgrid(parts)); } static void showPackedFrame(String title, Component contents) { packFrame(showFrame(title, contents)); } static JPanel vgrid(List parts) { return vgrid(asArray(parts)); } static JPanel vgrid(Object... parts) { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(parts.length, 1)); smartAdd(panel, parts); return panel; } static Object[] asArray(List l) { return toObjectArray(l); } static int packFrame_minw = 150, packFrame_minh = 50; static void packFrame(JFrame frame) { frame.pack(); frame.setSize( max(frame.getWidth(), packFrame_minw), max(frame.getHeight(), packFrame_minh)); } static void smartAdd(JPanel panel, Object... parts) { for (Object o : parts) { Component c; if (o instanceof String) c = new JLabel((String) o); else if (o instanceof Component) c = wrap((Component) o); else continue; panel.add(c); } } static JFrame showFrame() { return makeFrame(); } static JFrame showFrame(Component content) { return makeFrame(content); } static JFrame showFrame(String title) { return makeFrame(title); } static JFrame showFrame(String title, Component content) { return makeFrame(title, content); } static int max(int a, int b) { return Math.max(a, b); } static long max(int a, long b) { return Math.max((long) a, b); } static long max(long a, long b) { return Math.max(a, b); } static double max(int a, double b) { return Math.max((double) a, b); } static int max(Collection c) { int x = Integer.MIN_VALUE; for (int i : c) x = max(x, i); return x; } static double max(double[] c) { if (c.length == 0) return Double.MIN_VALUE; double x = c[0]; for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]); return x; } static byte max(byte[] c) { byte x = -128; for (byte d : c) if (d > x) x = d; return x; } static JFrame makeFrame() { return makeFrame((Component) null); } static JFrame makeFrame(Component content) { // TODO: get program ID return makeFrame("A JavaX Frame", content); } static JFrame makeFrame(String title) { return makeFrame(title, null); } static JFrame makeFrame(String title, Component content) { JFrame frame = new JFrame(title); if (content != null) frame.getContentPane().add(content); frame.setBounds(300, 100, 500, 400); frame.setVisible(true); //exitOnFrameClose(frame); return frame; } static Object[] toObjectArray(List list) { return list.toArray(new Object[list.size()]); } static Component wrap(Component c) { if (c instanceof JTable || c instanceof JList || c instanceof JTextArea) return new JScrollPane(c); return c; } }