java - 在MVC模式中,在View部分使用构建器模式是否合适

标签 java swing model-view-controller builder

public class AddFormConcreteBuilder extends FormBuilder
{
    private JDateChooser dateChooser;
    private InsertProducer producer;
    private DataObject dataObject;
    private JTextField AssetName;   
    private JTextField Financial;   
    private JTextField Location;
    private JComboBox Custodian;
    private JComboBox Type;
    private JComboBox RetentionPeriod;
    private JComboBox MaintenanceSched;
    private JComboBox Confidentiality;
    private JComboBox Integrity;
    private JComboBox Availability;
    private JComboBox Classification;
    private JButton btnConfirm;
    private JButton btnBack; 
    private ArrayList<DataSet> insertList = new ArrayList<DataSet>();
    private int AssetID = generateNewAssetID();


    private PanelManager PanelHolder;
    /**
     * @wbp.parser.entryPoint
     */
    @Override
    public void buildComponents()
    {
        PanelHolder = new PanelManager();
        ComboBoxManager comboModelCreator= new ComboBoxManager();
        myForm.setSize(1200,644);
        myForm.setLayout(null);

        Custodian = new JComboBox(comboModelCreator.CustodianData());
        Custodian.setBounds(135, 130, 144, 20);
        myForm.add(Custodian);

        Type = new JComboBox(comboModelCreator.TypeData());
        Type.setBounds(135, 163, 144, 20);
        myForm.add(Type);

        RetentionPeriod = new JComboBox(comboModelCreator.RetentionPeriodData());
        RetentionPeriod.setBounds(161, 230, 118, 20);
        myForm.add(RetentionPeriod);

        MaintenanceSched = new JComboBox(comboModelCreator.MaintenanceSchedData());
        MaintenanceSched.setBounds(161, 274, 118, 20);
        myForm.add(MaintenanceSched);

        Confidentiality = new JComboBox(comboModelCreator.ConfidentialityData());
        Confidentiality.setBounds(161, 354, 118, 20);
        myForm.add(Confidentiality);

        Integrity = new JComboBox(comboModelCreator.IntegrityData());
        Integrity.setBounds(161, 393, 118, 20);
        myForm.add(Integrity);

        Availability = new JComboBox(comboModelCreator.AvailabilityData());
        Availability.setBounds(161, 429, 118, 20);
        myForm.add(Availability);

        Classification = new JComboBox(comboModelCreator.ClassificationData());
        Classification.setBounds(161, 467, 118, 20);
        myForm.add(Classification);

        JLabel lblAssetName = new JLabel("Asset Name : ");
        lblAssetName.setBounds(24, 92, 101, 24);
        myForm.add(lblAssetName);

        AssetName = new JTextField();       
        AssetName.setBounds(135, 94, 144, 20);      
        myForm.add(AssetName);
        AssetName.setColumns(10);

        JLabel lblCustodian = new JLabel("Custodian :");
        lblCustodian.setBounds(24, 128, 75, 24);
        myForm.add(lblCustodian);

        JLabel lblType = new JLabel("Type :");
        lblType.setBounds(24, 166, 60, 14);
        myForm.add(lblType);

        JLabel DateAcquired = new JLabel("Date Acquired :");
        DateAcquired.setBounds(24, 191, 101, 24);
        myForm.add(DateAcquired);

        JLabel lblRetentionPeriod = new JLabel("Retention Period :");
        lblRetentionPeriod.setBounds(24, 236, 118, 14);
        myForm.add(lblRetentionPeriod);

        JLabel MaintenanceSchedlbl = new JLabel("Maintenance Schedule : ");
        MaintenanceSchedlbl.setBounds(24, 275, 153, 24);
        myForm.add(MaintenanceSchedlbl);

        JLabel lblFinancial = new JLabel("Financial : ");
        lblFinancial.setBounds(24, 310, 90, 24);
        myForm.add(lblFinancial);

        Financial = new JTextField();
        Financial.setBounds(135, 309, 144, 20);     
        myForm.add(Financial);
        Financial.setColumns(10);

        JLabel Confidential = new JLabel("Confidentiality: ");
        Confidential.setBounds(24, 355, 127, 24);
        myForm.add(Confidential);

        JLabel lblIntegrity = new JLabel("Integrity :");
        lblIntegrity.setBounds(24, 399, 75, 14);
        myForm.add(lblIntegrity);

        JLabel lblAvailability = new JLabel("Availability : ");
        lblAvailability.setBounds(22, 435, 103, 14);
        myForm.add(lblAvailability);

        JLabel lblClassification = new JLabel("Classification :");
        lblClassification.setBounds(24, 473, 118, 14);
        myForm.add(lblClassification);

        JLabel lblStorageLocation = new JLabel("Storage Location :");
        lblStorageLocation.setBounds(24, 507, 127, 14);
        myForm.add(lblStorageLocation);

        Location = new JTextField();                
        Location.setBounds(161, 501, 118, 20);

        myForm.add(Location);
        Location.setColumns(10);

        btnConfirm = new JButton("Confirm");        
        btnConfirm.setBounds(403, 524, 179, 49);
        btnConfirm.setFont(new Font("Dialog", Font.BOLD, 22));
        myForm.add(btnConfirm);

        btnBack = new JButton("Back");              
        btnBack.setBounds(629, 524, 180, 49);
        btnBack.setFont(new Font("Dialog", Font.BOLD, 22));
        myForm.add(btnBack);

        dateChooser = new JDateChooser();
        dateChooser.setBounds(143, 191, 136, 20);
        myForm.add(dateChooser);
    }

这是将用作 View 的示例具体构建器模式。因为是 builder 而不是景观,真的合适吗?对于设计模式我还是个新手。对此感到抱歉。不管怎样,谢谢!

最佳答案

我想说,构建器非常适合用作 View 的角色。

不过,问自己这并不是一个好问题。设计模式的存在是为了帮助您找到特定问题的解决方案,并使用通用词汇与其他人讨论这些问题。如果代码遵循良好的 OOP 原则,例如连贯性、一致性等,并且易于理解和维护,那么您的代码是否严格满足某些特定命名设计模式或其他的定义并不重要。

关于java - 在MVC模式中,在View部分使用构建器模式是否合适,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18405804/

相关文章:

javascript - 如何在 Sencha Touch 2 的 View 中定义自己的函数

java - 按钮未显示在我的 Jframe 中

java 使用 JPanel 的大小来调整组件的大小

java - 如何在j2me应用程序中设置连续工作量规条?塞类

带 GUI 的 Java 文字游戏。我的代码有什么问题吗?

java - 使用 JTree 进行 Swing Action

html - 如何将所需的 HTML 属性正确设置为 TymeLeaf 页面中的输入标记?

MySQLSyntaxErrorException : Unknown column in 'field list'

java - 进度对话框阻止内容 View 切换?

java - 由于空指针异常,应用程序崩溃