//mainFrame.java // generates a frame to cover the screen for the text. //Title: General Classes //Version: 0.1 //Author: John Krantz //Company: Hanover College //Description: Some general classes to control the look and feel //of the book package. package util; import java.awt.*; import javax.swing.*; /** * Contructs a screen size frame with the defaults already inplace * base upon JFrame. * @author John Krantz * @version 0.1 */ public class SelectionFrame extends JFrame { static final long serialVersionUID = 0; public final static Dimension SCREENSIZE = Toolkit.getDefaultToolkit().getScreenSize(); // contaner to hold panel private Container c = this.getContentPane(); //Panel object to hold parameters to be set private JPanel titlePanel = new JPanel(new BorderLayout()); private JPanel holdPanel = new JPanel(); // title object private JLabel titleLabel = new JLabel("Title"); // parameter object private JCheckBox param [] = new JCheckBox[3]; // done button public JButton applyButton = new JButton("Apply"); public JButton doneButton = new JButton("Done"); // add a title to the same frame as above. public SelectionFrame(String title, String [] paramNames, boolean [] paramDefaults){ Font titleFont = new Font("SansSerif",Font.BOLD,18); Font labelFont = new Font("SansSerif",Font.PLAIN,12); titleLabel.setFont(titleFont); titleLabel.setText(title); // parameters to determine the size of the window int h = 0; int w = 0; FontMetrics fm = titleLabel.getFontMetrics(titleFont); h = fm.getHeight(); w = fm.stringWidth(titleLabel.getText()); fm = titleLabel.getFontMetrics(labelFont); this.getContentPane().setBackground(Color.black); this.setForeground(Color.white); this.setTitle(titleLabel.getText()); // set primary layout c.add(titlePanel,BorderLayout.NORTH); titlePanel.add(titleLabel,BorderLayout.CENTER); c.add(holdPanel,BorderLayout.CENTER); // set up the parameters objects param = new JCheckBox[paramNames.length]; holdPanel.setLayout(new GridLayout(param.length,1)); // add the parameter objects for (int i = 0; i < param.length; i ++){ param[i] = new JCheckBox(paramNames[i],paramDefaults[i]); holdPanel.add(param[i]); h += fm.getHeight(); if (fm.stringWidth(param[i].getText()) > w){ w = fm.stringWidth(param[i].getText()); } } // add the done button JPanel donePanel = new JPanel(new FlowLayout()); donePanel.add(applyButton); donePanel.add(doneButton); c.add(donePanel, BorderLayout.SOUTH); h += fm.getHeight(); this.setSize(new Dimension(w*20/10,h*20/10)); } // get methods public boolean [] getParameters(){ boolean [] out = new boolean[param.length]; for (int i = 0; i < param.length; i ++){ out[i] = param[i].isSelected(); } return out; } public int getFrameHeight(){ return getHeight();} public int getFrameWidth(){ return getWidth();} }