In my program there are 10 connections in connectionList. For each connection I create my frames again. It means I create the same frame for 10 times. I want to create it only 1 time and use it for 10 times,not create for each connection. I can not design it. I sent my part of code about create frame. Could you make only one example among them for me. Should I use Singleton Pattern? What is the solution way and how should make it? Because in real program I have 25 frames like that. If you make one of these I can do other 24 frames. Best Regards
Main Class
for (String wn : connectionList) {
if (!workSpacesNames.contains(wn)) {
try {
DWorkspace workSpace = new DWorkspace(wn, DMainFrame.this);
workSpaces.add(workSpace);
tabbedPane.addTab(workSpace.getTitle(), workSpace.getHolderPanel());
workSpace.getDockingManager().setShowWorkspace(showWorkspaceArea);
workSpace.getDockingManager().beginLoadLayoutData();
if (UserAuthorization.getUserAuth().isAuthorized(CommandAuthType.CANCELEDORDERS_WINDOW)) {
workSpace.getDockingManager().addFrame(DFrameFactory.createClosedOrderTable(
workSpace, canceledOrderSound, DockContext.STATE_HIDDEN));
}
if (UserAuthorization.getUserAuth().isAuthorized(CommandAuthType.CANCELEDSTRATEGIES_WINDOW)) {
workSpace.getDockingManager().addFrame(DFrameFactory.createClosedStrategyTable(
workSpace, canceledStrategySound, DockContext.STATE_HIDDEN));
}
}
catch (Exception ex) {
log.trace("exception in DMainFrame", ex);
}
}
}
Create Frames Class
public class DFrameFactory {
private DFrameFactory() {
}
public static DockableFrame createClosedOrderTable(DWorkspace workspace,JCheckBoxMenuItem canceledOrderSound, int context) {
DockableFrame frame = new DockableFrame("closedorders");
frame.setTitle(ELanguage.getString("(LANG)org.neyre.dallar.frame.framefactory.closedorders.title"));
frame.setTabTitle(
ELanguage.getString("(LANG)org.neyre.dallar.frame.framefactory.closedorders.tabtitle"));
frame.setSideTitle(ELanguage.getString(
"(LANG)org.neyre.dallar.frame.framefactory.closedorders.sidetitle"));
frame.getContext().setInitMode(context);
frame.getContext().setInitSide(DockContext.DOCK_SIDE_SOUTH);
frame.getContext().setInitIndex(1);
frame.getContentPane().add(new DFClosedOrderTable(workspace, canceledOrderSound));
frame.setPreferredSize(new Dimension(750, 300));
frame.setDockedWidth(750);
frame.setFrameIcon(EIcons.getSmallIcon(EIcons.ERROR));
return frame;
}
public static DockableFrame createClosedStrategyTable(DWorkspace workspace,JCheckBoxMenuItem canceledStrategySound, int context) {
DockableFrame frame = new DockableFrame("closedstrategies");
frame.setTitle(ELanguage.getString("(LANG)org.neyre.dallar.frame.framefactory.closedstrategies.title"));
frame.setTabTitle(
ELanguage.getString("(LANG)org.neyre.dallar.frame.framefactory.closedstrategies.tabtitle"));
frame.setSideTitle(ELanguage.getString(
"(LANG)org.neyre.dallar.frame.framefactory.closedstrategies.sidetitle"));
frame.getContext().setInitMode(context);
frame.getContext().setInitSide(DockContext.DOCK_SIDE_SOUTH);
frame.getContext().setInitIndex(1);
frame.getContentPane().add(new DFClosedStrategyTable(workspace, canceledStrategySound));
frame.setPreferredSize(new Dimension(750, 300));
frame.setDockedWidth(750);
frame.setFrameIcon(EIcons.getSmallIcon(EIcons.ERROR));
return frame;
}
}
Aucun commentaire:
Enregistrer un commentaire