简体   繁体   中英

Displaying GUI frame with Swing

The problem at this present time: 在此处输入图片说明

What the output should be:

在此处输入图片说明

I believe I have to simply add the main() within the bmiCalculatorFrame instead of the one I've made but not sure on how this is done as doing so causes many more errors.

code, http://pastebin.com/raw.php?i=svTUwufa

I know it is a lot of lines and not very specific but it is the best way to explain the predicament I am in.

The root of your evil, i guess, can be found in this lines:

private void initComponents() {
    JFrame bmiCalculatorFrame = new JFrame();

You are adding all your components to bmiCalculatorFrame , but in the main method, you instanciate your class which is extending JFrame by itself. The shortest way to reach your goal is in my eyes to alter the following lines:

bmiCalculatorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        bmiCalculatorFrame.setTitle("BMI Calculator");
Container bmiCalculatorFrameContentPane = bmiCalculatorFrame.getContentPane();

to use this instead of bmiCalculatorFrame .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM