简体   繁体   English

使用Swing显示GUI框架

[英]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. 我相信我必须在bmiCalculatorFrame内简单地添加main()而不是我自己做的,但是不确定这样做是如何做的,因为这样做会导致更多错误。

code, http://pastebin.com/raw.php?i=svTUwufa 代码, 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. 您将所有组件添加到bmiCalculatorFrame ,但是在main方法中,您实例化了自己扩展JFrame的类。 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 . this代替bmiCalculatorFrame

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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