All pastes #414296 Raw Edit

Plouj

public java v1 · immutable
#414296 ·published 2007-03-28 23:03 UTC
rendered paste body
import java.awt.*;import java.awt.event.*;import javax.swing.*;// see TODO.txt for what needs to be donepublic class A31 implements ActionListener {	private final static String title = "A31 - 3NF Synthesizer";	// labels	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";	// constants	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;	// UI components	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);		inputPanel = setupInputPanel();		c.fill=GridBagConstraints.BOTH;		c.gridwidth=2;		c.gridheight=GridBagConstraints.REMAINDER;		c.weightx=1.0; c.weighty=1.0;		c.gridx=0; c.gridy=3;		appPanel.add(inputPanel, c);		outputPanel = setupOutputPanel();		c.fill=GridBagConstraints.BOTH;		c.gridwidth=GridBagConstraints.REMAINDER;		c.gridheight=GridBagConstraints.REMAINDER;		c.weightx=1.0; c.weighty=1.0;		c.gridx=2; c.gridy=3;		appPanel.add(outputPanel, 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();			}		});	}}