Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Cannot update Jlabel in JApplet

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot update Jlabel in JApplet

     
    public class game extends JApplet {
     
     
    	private roll mygame;
    	private JLabel result;
    	public game(){
     
                             setLayout(new BorderLayout());
     
    	    result.setFont(new Font("Sansserif", Font.PLAIN, 14));
    	    getContentPane().add(result,BorderLayout.NORTH);
     
     
    	    mygame = new roll();
     
    	    getContentPane().add(mygame,BorderLayout.CENTER);	
    	}
    	public void start(){
     
    		 result.setText(""+mygame.score);
    		setSize(240, 300);
    	}
    	public void stop(){
     
    	}
    	public void destroy(){
     
    	}
     
     
    }

    What is wrong with my code?
    Is it impossible for JApplet to derived value for JPanel?
    All the system is on JPanel (roll class).
    When the score become zero, I think to set the close system in void stop()~
    ?? My idea is correct??


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Cannot update Jlabel in JApplet

    Not really sure what it is you're asking for...

    First of all, you really don't want to create your own constructor for applets. The initializations should be done in the init() method (the start can kind of be used for this purpose, but for the most part I kind of leave this method alone).

    Also, whenever you make some change to a GUI interface (such as drawing an animation or , you should be calling update(), which will repaint the applet.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot update Jlabel in JApplet

    well, I think about paint(graphic g) -> repaint()/update()
    but the problem that I found is when repaint()
    the whole applet was reset and it become blank.
    I set all game function in JPanel which JApplet will call at my init() [thanks for correcting]
    The score Label can update inside JPanel well.
    But when the gameover, How can I make it over?
    I want to set the condition like when score= something then
    JApplet will go to win or lose (html page).

    I think about how to derived value form JPanel to JApplet.
    Since I found the JLabel in JApplet that I set to show value of JPanel Class did not update
    so I think that the derived process is fail.

    Can you give me a hint?

Similar Threads

  1. JApplet containing JButton and a JLabel
    By JuneM in forum AWT / Java Swing
    Replies: 3
    Last Post: March 26th, 2010, 08:32 AM
  2. Funny business with JFrame, JPanel and JLabel
    By JeffC in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2010, 01:26 PM
  3. how to output using JLabel?
    By qaromi in forum AWT / Java Swing
    Replies: 1
    Last Post: August 30th, 2009, 02:09 PM