The following listings are the 2 constructors I am using as of now to make everything work.
Constructor 1:
Code:
public EmailFrame()
{
openFrameCount++;
setTitle("Email Message " + openFrameCount);
JPanel top = new JPanel();
top.setBorder(new EmptyBorder(10, 10, 10, 10));
top.setLayout(new BorderLayout());
top.add(buildAddressPanel(), BorderLayout.NORTH);
content = new JTextArea( 15, 30 );
content.setBorder( new EmptyBorder(0,5 ,0, 5) );
content.setLineWrap(true);
JScrollPane textScroller = new JScrollPane(content, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
top.add( textScroller, BorderLayout.CENTER);
JButton sendBtn = new JButton("Send");
top.add(sendBtn, BorderLayout.SOUTH);
sendBtn.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
sendBtnItemActionPerformed(evt);
}
});
setContentPane(top);
pack();
}
Constructor 2:
Code:
public EmailFrame(String emailToField, String subjField, String bodytext)
{
openFrameCount++;
setTitle("Email Message " + openFrameCount);
JPanel top = new JPanel();
top.setBorder(new EmptyBorder(10, 10, 10, 10));
top.setLayout(new BorderLayout());
top.add(buildAddressPanel(), BorderLayout.NORTH);
toField.setText(emailToField); // Extra
toField.setEditable(false); // Extra
subField.setText(subjField); // Extra
subField.setEditable(false); // Extra
content = new JTextArea( 15, 30 );
content.setBorder( new EmptyBorder(0,5 ,0, 5) );
content.setLineWrap(true);
content.setText(bodytext);
JScrollPane textScroller = new JScrollPane(content, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
top.add( textScroller, BorderLayout.CENTER);
JButton sendBtn = new JButton("Send");
top.add(sendBtn, BorderLayout.SOUTH);
sendBtn.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
sendBtnItemActionPerformed(evt);
}
});
setContentPane(top);
pack();
}
The lines marked extra are the lines that are different. So the idea is to have the lowest common denominator in one constructor and the mods in the rest. The only way I can think of by achieving this is by doing:
Code:
Public EmailFrame()
{
initGUIComponents(); // dump gui code here
}
And the second constructor would be:
Code:
Public EmailFrame()
{
initGUIComponents(); // dump gui code here
// the lines of code that are commented as extra
}
Is that right Kezzer? That what you would recommend?