There are not compiling errors now, the value wont show, only the message "number:" I've already been here, for the exception that before it shown "number:NULL" but i think i am getting there... thanks to all of you. I've been reading threads for about a week, but i learned more tonight with you advises
Login class
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);
}
}
This is the playerregistration panel
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);
}
}
There is a JLabel asking the user to input a number, up to this point a String, then user is supposed to click the playerregistrationJB, and the number appearing in the PlayerRegistration_JPanel.
Also, there is a ProccessedJPanel where i call all my buttons by ActionListener,
also a finalJpanel where i have my main in one frame. I don't know where is the problem since my JTextField is global (though we don't have any such thing like GLOBAL VARIABLE in Java).
You didn't declare useraccountnumberJTF in the class PlayerRegistration_JPanel (it's declared only in Login_JPanel class) yet you call it in this line. This is your error.
Where is your useraccountnumberJTF. You have declare it in another class. In order to acces the other class property, you must create oject of other class in your class and then access the other class property. Also both the class must be in same package.
public class PlayerRegistration_JPanel extends JPanel
{
Login_JPanel login = new Login_JPanel();
public PlayerRegistration_JPanel()
{
add(useraccountnumberJL);
useraccountnumberJL.setText(login.useraccountnumberJTF.getText());
useraccountnumberJL.setBounds( 100, 75, 625, 200 );
useraccountnumberJL.setFont( new Font( "Broadway", Font.BOLD, 18 ) );
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With