0

I am looking to use the Factory Method Pattern in order to make the development of my Swing UI quicker and more manageable.

In general, its an MDI application using JInternalFrames. I have a lot of settings, types as I call them, in the system (Eg. userTypes, accountTypes, etc.) I have a fixed UI which I've decided to use. Thing is, there are over 50 of these types in the system, so the factory method pattern seems to be the most manageable solution. Below are two screenshots of a working app.

main part of a record enter image description here

I was looking at [this example][3] but since I wont be able to estimate the number of tabs I would require to store all info in a record, I would need to be able to add multiple tabs and controls (labels, textboxes, tables, comboboxes, etc.) within these tabs.

Based on the example, is it possible to create a JTabbedPane in the abstract class and modify and add to it in the subclasses? I tried the following and am a bit lost:

public AbstractTypeInternalFrame(String title) {
        setBounds(100, 100, 808, 589);

        JToolBar toolBar = new JToolBar();
        getContentPane().add(toolBar, BorderLayout.NORTH);

        JButton btnAdd = new JButton("Add");
        toolBar.add(btnAdd);

        JButton btnSave = new JButton("Save");
        btnSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        toolBar.add(btnSave);

        JButton btnDelete = new JButton("Delete");
        toolBar.add(btnDelete);

        JButton btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        toolBar.add(btnCancel);

        JTabbedPane recordTabs = new JTabbedPane(makeRecordTabPane());
        getContentPane().add(recordTabs, BorderLayout.NORTH);

        JSeparator recordSearchSeparator = new JSeparator();
        getContentPane().add(recordSearchSeparator, BorderLayout.NORTH);



    }

    protected abstract int makeRecordTabPane();

with the method makeRecordTabPane() require to return an int.

As you can see, I'm a little lost and just need some direction as to how to proceed with such a pattern. If any has any advice or even examples/links, it would be much appreciated.

I realize my question is vague, so if any clarification is required on my side, please feel free to ask.

Best regards.

greatkalu
  • 433
  • 1
  • 8
  • 21
  • 1
    At least accept nice cow's answer in your [previous question](http://stackoverflow.com/questions/10246511/mvc-implementation-of-java-swing-focuslistener) given the amount of effort he expended in trying to help you. And then yes, please try to clarify this question greatly. Start by assuming that we know nothing about your program and that we can't see code that is not shown, nor read minds. – Hovercraft Full Of Eels May 30 '12 at 14:48
  • 1
    See also [*Item 1: Consider static factory methods instead of constructors*](http://www.drdobbs.com/jvm/208403883). – trashgod May 30 '12 at 16:53
  • read this: http://stackoverflow.com/questions/15202590/using-factory-pattern-in-java – Diego Rodriguez Mar 04 '13 at 14:35

1 Answers1

0

Here is the question in more detail.

So, I am looking to build a simple JInternalFrame for CRUD operations on records on the system. Records such as users, usertypes, accounts, accountypes, etc. There are more than 50 of these types in the system, so I figure using the factory method pattern would make all these JInternalFrames more manageable.

Here is an example of a user record:

Link1 Link2

The top half constitutes of the details of a record, which are split into tabs depending on the contents of the record. Some records may have just one tab, while other larger ones will have multiple. Therefore, the contents of the JTabbedPane should be instantiated at the subclass level and per this example.

The bottom part is where we would search for records of that type. Say for example, in the links posted, the User Manager JInternalFrame is opened. We then would search for users according to username and/or userID. Results are displayed in the table below and on double-clicking a search result, the record is displayed above in the JTabbedPane.

Add, Save, Delete and Cancel buttons are then used to perform CRUD operations on whatever is entered into the record.

From this, we can say that the aspects of the design than need to be instantiated by subclasses are:

1) Size of the JInternaFrame 2) All contents of the JTabbedPane: no of tabes, tables, labels, textboxes, etc. 3) The number of columns in the search result JTable: which we can change by instantiating the JTable Header.

As a start, I was trying to just create an Abstract class with a JTabbedPane, and add components to the JTabbedPane to see how I could go about it. This is the code I posted earlier. This file was generated using WindowBuilder, which I later then modified:

package zm.co.freight.fpsManagementGUI.view;

import java.awt.EventQueue;

public abstract class AbstractTypeInternalFrame extends JInternalFrame {

    /**
     * Launch the application.
     */
//  public static void main(String[] args) {
//      EventQueue.invokeLater(new Runnable() {
//          public void run() {
//              try {
//                  AbstractTypeInternalFrame frame = new AbstractTypeInternalFrame();
//                  frame.setVisible(true);
//              } catch (Exception e) {
//                  e.printStackTrace();
//              }
//          }
//      });
//  }

    /**
     * Create the frame.
     */
    public AbstractTypeInternalFrame(String title) {
        setBounds(100, 100, 808, 589);

        JToolBar toolBar = new JToolBar();
        getContentPane().add(toolBar, BorderLayout.NORTH);

        JButton btnAdd = new JButton("Add");
        toolBar.add(btnAdd);

        JButton btnSave = new JButton("Save");
        btnSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        toolBar.add(btnSave);

        JButton btnDelete = new JButton("Delete");
        toolBar.add(btnDelete);

        JButton btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        toolBar.add(btnCancel);

        JTabbedPane recordTabs = new JTabbedPane(makeRecordTabPane());
        getContentPane().add(recordTabs, BorderLayout.NORTH);

        JSeparator recordSearchSeparator = new JSeparator();
        getContentPane().add(recordSearchSeparator, BorderLayout.NORTH);



    }

    protected abstract int makeRecordTabPane();

}

The question is, am I on the right track? How should I approach it using the factory method pattern as I don't seem to grasp it very well. I've seen simpler examples, with shapes and drawings, but am a bit lost with Swing interfaces. Is there a good example you could direct me to or a simple example just to point me in the right direction ... thats all I was asking for. Sorry if it was vague ...

greatkalu
  • 433
  • 1
  • 8
  • 21
  • This space is usually reserved for questions - StackOverflow being a Q&A web site. You could add this to your question using an edit. – James P. Mar 19 '13 at 01:27