Results 1 to 8 of 8

Thread: My JLabels.

  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default My JLabels.

    Hey im creating another application, and this is a weird situation because i did this before but now it's not working.

    In my actionlistener i use a JLabel, and use the setText() method.

    Normally this works, but now it doesn't because when i actually click the button it is supposed to set the text of the label. but it doesn't.

    This is the code:

    Java Code:
    final JButton btnNewButton = new JButton("Calculate!");
    		btnNewButton.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent arg0){
    			
    					int xp = Integer.parseInt(textField.getText());
    					int xp2 = Integer.parseInt(textField_1.getText());
    				    double xpleft = xp2 - xp;
    					double logleft = xpleft / 12500;
    					double percentage = (xp /xp2)*100;
    					lblNewLabel_4.setText(""+xpleft);
    					label.setText(""+logleft);
    					
    					
    					
    					
    				
    			}
    		});
    		btnNewButton.setBounds(10, 205, 121, 50);
    		panel.add(btnNewButton);
    		btnNewButton.setIcon(img3);
    Never give up.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: My JLabels.

    System.out.println( ... ) the value of logleft and xpleft near the end of that method and see if they make any sense (and if anything is printed at all).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: My JLabels.

    Quote Originally Posted by JosAH View Post
    System.out.println( ... ) the value of logleft and xpleft near the end of that method and see if they make any sense (and if anything is printed at all).

    kind regards,

    Jos
    Yeah man that worked, i tried that before.
    But i fixed it now, i moved them out of the anonymous inner class, into a normal ActionListener class.

    Thanks anyways :)
    Never give up.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: My JLabels.

    Quote Originally Posted by MR bruto View Post
    Yeah man that worked, i tried that before.
    But i fixed it now, i moved them out of the anonymous inner class, into a normal ActionListener class.

    Thanks anyways :)
    I don't understand how that might have helped; you must've changed something else too ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: My JLabels.

    Quote Originally Posted by JosAH View Post
    I don't understand how that might have helped; you must've changed something else too ...

    kind regards,

    Jos
    I seriously didn't, i don't get what's going on either. Since it always worked.

    but whatever
    Never give up.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: My JLabels.

    Quote Originally Posted by MR bruto View Post
    I seriously didn't, i don't get what's going on either. Since it always worked.

    but whatever
    Programming must be a super natural experience for you; don't forget the garlic.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: My JLabels.

    Quote Originally Posted by JosAH View Post
    Programming must be a super natural experience for you; don't forget the garlic.

    Jos
    Well, Larry Wall compared programming to cooking after all.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: My JLabels.

    Quote Originally Posted by superhaNds View Post
    Well, Larry Wall compared programming to cooking after all.
    He's the guy who wrote that write-only-language; say no more ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need some help with JLabels.
    By Medabi3 in forum Java Applets
    Replies: 1
    Last Post: 08-24-2011, 07:28 PM
  2. Overlapping JLabels
    By littledrummerboy in forum New To Java
    Replies: 4
    Last Post: 05-24-2011, 04:47 PM
  3. can i have a JList of Jlabels?
    By chayan in forum AWT / Swing
    Replies: 3
    Last Post: 07-04-2010, 12:19 AM
  4. Overlapping JLabels
    By techbossmb in forum AWT / Swing
    Replies: 3
    Last Post: 09-21-2009, 03:21 PM
  5. problem with JLabels
    By geork in forum New To Java
    Replies: 3
    Last Post: 01-31-2008, 02:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •