Howdy. My question is: is it ok to continue to create the my calc program in the static method main or should i have a calc class with constructs extending JFrame and having static main method instantiate calc and having the windowlistener in it? can i do it both ways? and what are the benefits of both? thanks. here is the code:
import javax.swing.*;
import java.awt.*;
import
java .awt.event.*;
public class Calc {
public static void main(
String args[]) {
JButton jb[];
String jbNames[] = {"1", "2", "3", "=", "4", "5", "6", "+", "7", "8", "9", "-", "0",
".", "C", "*", "MR", "MC", "M+", "/"};
JFrame jf = new JFrame("Caluculator");
JTextField tf = new JTextField();
JPanel jp = new JPanel (true);
jp.setLayout(new GridLayout(5, 4, 2, 2));
jb = new JButton[jbNames.length];
for (int i = 0; i < jbNames.length; i++) {
jb[i] = new JButton(jbNames[i]);
jp.add(jb[i]);
}
jf.getContentPane().add(tf, BorderLayout.NORTH);
jf.getContentPane().add(jp, BorderLayout.CENTER);
jf.pack();
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
jf.setVisible(true);
}
}