现在没有编译错误,值不会显示,只有消息“数字:”我已经在这里,除了之前显示“数字:NULL”但我想我到了那里......感谢你们所有人。我已经阅读了大约一个星期的主题,但我今晚在你的建议下学到了更多
登录类
public class Login_JPanel extends JPanel
{
JLabel welcomeMessage,
mainPicture;
JButton playerregistrationJB = new JButton ( "Player Registration" );
JLabel userAccountNumberJLabel = new JLabel("<HTML><CENTER><FONT SIZE=6
COLOR=YELLOW>Please, enter your account number below and then click on player
registration to continue </COLOR></CENTER></HTML>");
JTextField useraccountnumberJTF = new JTextField();
public Login_JPanel()
{
//========================================================
//SET UP USERNAME JLABEL AND TEXT FIELD
//========================================================
add(userAccountNumberJLabel);
userAccountNumberJLabel.setBounds( 322, 335, 300, 155 );
add(useraccountnumberJTF);
useraccountnumberJTF.setBounds (330, 500, 90, 25 );
playerregistrationJB.setBounds( 350, 600, 325, 75 );
playerregistrationJB.setFont( new Font( "Broadway", Font.BOLD, 30 ) );
playerregistrationJB.setForeground( Color.red );
playerregistrationJB.setBackground( Color.YELLOW );
add( playerregistrationJB);
add( welcomeMessage = new JLabel( "Welcome!!" ) );
welcomeMessage.setBounds(0,0,50,23);
add( mainPicture = new JLabel( new ImageIcon("henkidama.jpg") ) );
mainPicture.setBounds(0,0,50,50);
setLayout(null);
setBounds(0,0,1000,800);
}
}
这是玩家注册面板
public class PlayerRegistration_JPanel extends JPanel
{
Login_JPanel loginJP = new Login_JPanel();
JLabel welcomeMessage,
mainPicture;
JLabel useraccountnumberJL = new JLabel();
JButton submitJB = new JButton ( "Submit" );
public PlayerRegistration_JPanel()
{
add(useraccountnumberJL);
useraccountnumberJL.setText("number: " +
loginJP.useraccountnumberJTF.getText());
useraccountnumberJL.setBounds( 100, 75, 625, 200 );
useraccountnumberJL.setFont( new Font( "Broadway", Font.BOLD, 18 ) );
submitJB.setBounds( 350, 600, 325, 75 );
submitJB.setFont( new Font( "Broadway", Font.BOLD, 30 ) );
submitJB.setForeground( Color.red );
submitJB.setBackground( Color.YELLOW );
add( submitJB);
add( welcomeMessage = new JLabel( "Welcome to Building Another Panel!!" ) );
welcomeMessage.setBounds(0,0,50,23);
add( mainPicture = new JLabel( new ImageIcon("henkidama.jpg") ) );
mainPicture.setBounds(0,0,50,50);
setLayout(null);
setBounds(0,0,1000,800);
}
}
有一个JLabel
要求用户输入一个数字,到此为止 a String
,然后用户应该点击playerregistrationJB
,并且数字出现在 中PlayerRegistration_JPanel
。此外,还有一个ProccessedJPanel
我用 调用所有按钮的地方ActionListener
,还有一个finalJpanel
我在一个框架中拥有我的主要按钮的地方。我不知道问题出在哪里,因为 myJTextField
是全局的(尽管我们在 Java 中没有像 GLOBAL VARIABLE 这样的东西)。