Ah, I didn't see the part about where you're using a tool to generate the code. I usually write my GUI's by hand, and the above code is what I would do by hand.
I guess it's ok with this code if it's generated, but I think it's a rather dumb way to generate the objects by calling the getter methods. I gave that tool a test, and it did generate the constructor for VisualTest. It also created VisualTest as a subclass of JFrame (I like this method because you have direct access to all the JFrame members).
Using that tool I generated this code (note that I still had to write the main method):
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class VisualTest extends JFrame
{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
/**
* This is the default constructor
*/
public VisualTest()
{
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize()
{
this.setSize(300, 200);
setContentPane(getJContentPane());
setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane()
{
if (jContentPane == null)
{
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJButton(), BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton()
{
if (jButton == null)
{
jButton = new JButton();
}
return jButton;
}
public static void main(String[] args)
{
VisualTest v = new VisualTest();
v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
v.setVisible(true);
}
}