📄 fieldview.java
字号:
package org.dbgen.view;import java.beans.*;import java.awt.event.*;import javax.swing.*;import org.dbgen.*;/** * View a single field definition. * */class FieldView extends JPanel implements PropertyChangeListener, ActionListener { org.dbgen.Field fieldField = null; JTextField fieldNameField = null; JComboBox fieldTypeComboBox = null; JTextField fieldLengthField = null; JTextField fieldScaleField = null; /** * FieldView constructor comment. */ public FieldView() { super(); initialize(); } /** * This method was created by a SmartGuide. * @param event java.awt.event.ActionEvent */ public void actionPerformed(ActionEvent event) { JTextField textField = (JTextField) event.getSource(); String text = textField.getText(); try { if (getNameField() == textField) { getField().setName(text); } else if (getLengthField() == textField) { getField().setLength(Integer.parseInt(text)); } else if (getScaleField() == textField) { getField().setScale(Integer.parseInt(text)); } } catch (NumberFormatException exception) { textField.selectAll(); } return; } /** * Gets the field property (org.dbgen.Field) value. * @return The field property value. * @see #setField */ public org.dbgen.Field getField() { /* Returns the field property value. */ if (fieldField == null) { try { fieldField = new org.dbgen.Field(); } catch (Throwable exception) { System.err.println("Exception creating field property."); } }; return fieldField; } /** * Gets the lengthField property (javax.swing.JTextField) value. * @return The lengthField property value. */ public JTextField getLengthField() { /* Returns the lengthField property value. */ if (fieldLengthField == null) { try { fieldLengthField = new JTextField(); } catch (Throwable exception) { System.err.println("Exception creating lengthField property."); } }; return fieldLengthField; } /** * Gets the nameField property (javax.swing.JTextField) value. * @return The nameField property value. */ public JTextField getNameField() { /* Returns the nameField property value. */ if (fieldNameField == null) { try { fieldNameField = new JTextField(); } catch (Throwable exception) { System.err.println("Exception creating nameField property."); } }; return fieldNameField; } /** * Gets the scaleField property (javax.swing.JTextField) value. * @return The scaleField property value. */ public JTextField getScaleField() { /* Returns the scaleField property value. */ if (fieldScaleField == null) { try { fieldScaleField = new JTextField(); } catch (Throwable exception) { System.err.println("Exception creating scaleField property."); } }; return fieldScaleField; } /** * Gets the typeComboBox property (javax.swing.JComboBox) value. * @return The typeComboBox property value. */ public JComboBox getTypeComboBox() { /* Returns the typeComboBox property value. */ if (fieldTypeComboBox == null) { try { fieldTypeComboBox = new JComboBox(); } catch (Throwable exception) { System.err.println("Exception creating typeComboBox property."); } }; return fieldTypeComboBox; } /** * Gets the typeComboBox property (javax.swing.JComboBox) value. * @return The typeComboBox property value. */ public JComboBox getTypeComboBox(java.util.Vector vector) { /* Returns the typeComboBox property value. */ if (fieldTypeComboBox == null) { try { fieldTypeComboBox = new JComboBox(vector); } catch (Throwable exception) { System.err.println("Exception creating typeComboBox property."); } }; return fieldTypeComboBox; } /** * This method was created by a SmartGuide. */ public void initialize() { setLayout(new java.awt.GridLayout(4, 2)); add(new JLabel("Field Name")); add(getNameField()); add(new JLabel("Field Type")); add(getTypeComboBox(new FieldTypes().getMap())); add(new JLabel("Field Length")); add(getLengthField()); add(new JLabel("Field Scale")); add(getScaleField()); getLengthField().setColumns(3); getScaleField().setColumns(3); getNameField().addActionListener(this); getLengthField().addActionListener(this); getScaleField().addActionListener(this); return; } /** * This method was created by a SmartGuide. * @param e PropertyChangeEvent */ public void propertyChange(PropertyChangeEvent e) { return; } /** * Sets the field property (org.dbgen.Field) value. * @param field The new value for the property. * @see #getField */ public void setField(org.dbgen.Field field) { /* FieldView is a listener of the Field object. -tt */ field.addPropertyChangeListener(this); /* Get the old property value for fire property change event. */ org.dbgen.Field oldValue = fieldField; /* Set the field property (attribute) to the new value. */ fieldField = field; /* Fire (signal/notify) the field property change event. */ firePropertyChange("field", oldValue, field); return; } /** * This method was created by a SmartGuide. * @param args java.lang.String[] */ public static void test(String args[]) { JFrame frame = new JFrame("Testing"); FieldView fv = new FieldView(); //view org.dbgen.Field field = new org.dbgen.Field(); //data fv.setField(field); frame.getContentPane().add(fv); frame.pack(); frame.show(); return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -