gpt4 book ai didi

java - JFrame 构建面板无法正常工作

转载 作者:行者123 更新时间:2023-12-02 02:20:46 25 4
gpt4 key购买 nike

我已尝试一切可能的方法来修复此错误。每次编译程序都会报错

KiloConverter.java:25: error: cannot find symbol 

如何解决这个错误?

import javax.swing.*; // Needed for swing classes

public class KiloConverter extends JFrame
{
private JPanel panel;
private JLabel messageLabel;
private JTextField kiloTextField;
private JButton calcButton;
private final int WINDOW_WIDTH = 310;
private final int WINDOW_HEIGHT = 100;


//constructor

public KiloConverter()
{
setTitle("Kilometer Converter");

setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//bulid the panel and add it to the frame
buildPanel();

//Add the panel to the frame's content page
add(panel);

setVisible(true);

}

//the bulid panel method adds a label, a text field,
//and a button to a panel

private void bulidPanel()
{
//Create a label to display instructions.

messageLabel = new JLabel("Enter a distance " + "in kilometers");

//Create a text field 10 characters wide.
kiloTextField = new JTextField(10);

//create a button with the caption CALCULATE
calcButton = new JButton("Calculate");

//create a JPanel object and let the panel field reference it
panel = new JPanel();


//Add the label, text fieldm and button components to the panel
panel.add(messageLabel);
panel.add(kiloTextField);
panel.add(calcButton);
}



public static void main (String[] args)
{

new KiloConverter();
}
}

最佳答案

所看到的源代码在两条注释和一个方法名称中将“build”错误地拼写为“bulid”。更正方法名称中的拼写应该可以解决问题,但更改所有三个实例。

关于java - JFrame 构建面板无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48534817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com