public class WhateverYourClassNameIs
{
public JButton btnConvert;
public static void main(String[] args)
{
//define the instance variable, this doesn't have to be in main
// it can be wherever you are initializing the code you're working on
btnConvert = new JButton("Convert");
}
}
1条答案
按热度按时间uurv41yg1#
如果按钮只是在一个方法中创建的,那么它将只在该方法的范围内可见,如果您试图在创建它的方法之外访问它,它将说它找不到按钮。相反,您可能希望使用一个示例变量,它如下所示: