//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.*; /** * constructs a frame to do a i/o dialog with elements * determined by the calling frame. * @author John Krantz * @version 0.1 */ public class DialogFrame extends MainFrame { static final long serialVersionUID = 0; public final static Dimension SCREENSIZE = Toolkit.getDefaultToolkit().getScreenSize(); // container 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"); // done button public JButton applyButton = new JButton("Apply"); public JButton doneButton = new JButton("Done"); // add a title to the same frame as above. public DialogFrame(String title, Component [] items){ 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 holdPanel.setLayout(new GridLayout(items.length,1)); // add the parameter objects for (int i = 0; i < items.length; i ++){ holdPanel.add(items[i]); h += fm.getHeight(); } // 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*30/10)); } // get methods public int getFrameHeight(){ return getHeight();} public int getFrameWidth(){ return getWidth();} }