All pastes #415023 Raw Edit

Anonymous

public java v1 · immutable
#415023 ·published 2007-03-29 13:52 UTC
rendered paste body
import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFormattedTextField;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;// see TODO.txt for what needs to be donepublic class A31 implements ActionListener {	private final static String title = "A31 - 3NF Synthesizer";	// lables	private final static String attributesLbl = "number of attributes: ";	private final static String FDsLbl = "number of FDs: ";	private final static String runFButtonLbl = "run F.txt";	private final static String runInputsButtonLbl = "run INPUTS";	private final static String inputTxtTitle = "given/generated FDs";	private final static String outputTxtTitle = "FDs in 3NF";	private final static int textFieldWidth = 150; // pixels	private final static int textFieldHeight = 20; // pixels	private final static int textAreaRows = 30;	private final static int textAreaColumns = 20;		private final static int GBLBorder = 1;	private JFrame appFrame;	private JPanel appPanel;	private JPanel inputPanel;	private JPanel outputPanel;		private JTextArea inputText;	private JTextArea outputText;		private JButton runFButton;	private JButton runInputsButton;	private JFormattedTextField attributesInput;	private JFormattedTextField FDsInput;	public A31() {		//Create and set up the window.		appFrame = new JFrame(title);		appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		//Create and set up the panel.		appPanel = new JPanel(new GridBagLayout());		addWidgets();		//Add the panel to the window.		appFrame.getContentPane().add(appPanel, BorderLayout.CENTER);		//Display the window.		appFrame.pack();		appFrame.setVisible(true);	}	private void addWidgets() {		GridBagConstraints c = new GridBagConstraints();		c.anchor = GridBagConstraints.LINE_START;		c.insets = new Insets(GBLBorder,GBLBorder,GBLBorder,GBLBorder);		c.gridx=0; 		c.gridy=0;		appPanel.add(new JLabel(attributesLbl), c);		attributesInput = setupAttributesInput();		c.gridx=1; c.gridy=0;		appPanel.add(attributesInput, c);				c.gridx=0; c.gridy=1;		appPanel.add(new JLabel(FDsLbl), c);		FDsInput = setupFDsInput();		c.gridx=1; c.gridy=1;		appPanel.add(FDsInput, c);				runFButton = new JButton(runFButtonLbl);		c.gridx=0; c.gridy=2;		appPanel.add(runFButton, c);		runInputsButton = new JButton(runInputsButtonLbl);		c.gridx=1; c.gridy=2;		appPanel.add(runInputsButton, c);		JPanel panel = new JPanel();		panel.setLayout(new GridLayout(1,2));				inputPanel = setupInputPanel();		panel.add(inputPanel);		outputPanel = setupOutputPanel();		panel.add(outputPanel);						c.fill = GridBagConstraints.BOTH;		c.gridwidth= GridBagConstraints.REMAINDER;		c.weightx = c.weighty = 1.0; 		c.gridx = 0; 		c.gridy = 3;		appPanel.add(panel, c);	}	private JFormattedTextField setupAttributesInput() {		JFormattedTextField field = new JFormattedTextField();		field.setValue(new Integer(0));		field.setMinimumSize(new Dimension(textFieldWidth,			textFieldHeight));		field.setPreferredSize(new Dimension(textFieldWidth,			textFieldHeight));		return field;	}	private JFormattedTextField setupFDsInput() {		JFormattedTextField field = new JFormattedTextField();		field.setValue(new Integer(0));		field.setMinimumSize(new Dimension(textFieldWidth,			textFieldHeight));		field.setPreferredSize(new Dimension(textFieldWidth,			textFieldHeight));		return field;	}	private JPanel setupInputPanel() {		JPanel panel = new JPanel(new BorderLayout());		panel.setBorder(BorderFactory.createTitledBorder(inputTxtTitle));				inputText = new JTextArea(textAreaRows, textAreaColumns);		inputText.setEditable(false);				JScrollPane pane = new JScrollPane(inputText);		panel.add(pane, BorderLayout.CENTER);		return panel;	}	private JPanel setupOutputPanel() {		JPanel panel = new JPanel(new BorderLayout());		panel.setBorder(BorderFactory.createTitledBorder(outputTxtTitle));				outputText = new JTextArea(textAreaRows, textAreaColumns);		outputText.setEditable(false);				JScrollPane pane = new JScrollPane(outputText);		panel.add(pane, BorderLayout.CENTER);		return panel;	}		private static void createAndShowGUI() {		//Make sure we have nice window decorations.		JFrame.setDefaultLookAndFeelDecorated(true);		A31 application = new A31();	}		public void actionPerformed(ActionEvent e) {	}	public static void main(String[] args) {		//Schedule a job for the event-dispatching thread:		//creating and showing this application's GUI.		javax.swing.SwingUtilities.invokeLater(new Runnable() {			public void run() {				createAndShowGUI();			}		});	}}