I need help. From a OO point of view in designing a GUI, what is the difference between the following code. Precisely, what is the significance of putting all those swing components as the the class private variables compared to defining them as variables only local to a method.
public class
test {
private JFrame frame;
private JPanel panel;
private JButton button = new JButton("hello");
public displayFrame()
{
frame = new JFrame();
Container content = frame.getContentPane();
panel = new JPanel();
panel.add(button);
content.add(panel);
frame.visible(true);
}
AND
public class test {
public displayFrame()
{
JFrame frame = new JFrame();
Container content = frame.getContentPane();
JPanel panel = new JPanel();
JButton button = new JButton("hello");
panel.add(button);
content.add(panel);
frame.visible(true);
}