I wish to display my gui in the main method however it doesn’t seem to do so…
I’ve used the suggestion here:
jformdesigner design it won't display?
But that did not work,
My error at the moment is that eclipse is suggesting I need to create a method called setDefaultCloseOperation which is already defined in the class and the same for the setvisible.
“The method setDefaultCloseOperation(int) is undefined for the type bmicalc
The method setVisible(boolean) is undefined for the type bmicalc”
main method:
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class iu {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
bmicalc GUI = new bmicalc();
GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GUI.setVisible(true);
}
});
class bmicalc extends JFrame{
public bmicalc() {
initComponents();
}
private void initComponents() {
JFrame bmiCalculatorFrame = new JFrame();
{
bmiCalculatorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
bmiCalculatorFrame.setTitle("BMI Calculator");
Container bmiCalculatorFrameContentPane = bmiCalculatorFrame.getContentPane();
bmiCalculatorFrameContentPane.setLayout(new GridLayout());
}
}}}}
Your
bmicalcclass should extendJFrame, but it is not.setDefaultCloseOperationandsetVisiblemethods belong toJFrame.Also, it is not very clear, but it looks like the JFormDesigner generated another
JFrame.EDIT:
Here is a example of
JFramegenerated by JFormDesigner:EDIT – according to the last question edit
To address your compilation issues see the snippet below. However, it is not clear what are you trying to achieve with
JFrame bmiCalculatorFrame.