Results 1 to 16 of 16
  1. #1
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default How to make image invisible and visible in applet

    hey guys my question is basic.

    How to make image invisible and visible in applet?

    here is the code of image
    Java Code:
    public void paint(Graphics g)  
    
    { 	super.paint(g);
    	try {base = getDocumentBase();
    images[0]=getImage(base,"Hangman.gif");
    } catch(Exception e){}
    
    g.drawImage(images[0],650,20,this);
    
    
    	  
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default Re: How to make image invisible and visible in applet

    Insert an if-statement?
    if(shouldPaint) {...draw your image...}

    in your "control" code you can change the variable shouldPaint and after that --> call repaint()

    btw: i would only draw the image at the paint method. I would load the image outside and only once!

  3. #3
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    i did hangman homework with gui now im doing it with applet

    everything are okey excepts images.

    i have 12 images. so i need to command which do invisible image.

    isnt there a commond like that ?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    Is an invisible image, an image that is not shown?
    In your paint method, if you return after the call to super.paint() no image will be shown. It will be invisible.

  5. #5
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    hey guys,finnally i convert my gui hangman code to applet hangman code.

    i put it on website here is the link:

    http://users9.jabry.com/ksbeyaz/

    sometimes pictures is reload slowly.

    i want your feedbacks.
    note(All text you must find is on "Turkish Words")

  6. #6
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    Although i upload all neccassary files ,if i dont enter website from my computer ,some part of this java homework dont be seen from different computers.

    why this problem occur?

    any suggestions?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    some part of this java homework dont be seen from different computers.
    Please explain.
    Also can you add a language choice and add English, I spent one winter in Izmir but did not learn much Turkish.

  8. #8
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    yeah i will do it.but homework was for Turkish.

    i have entered url with different computer and there should be ___ ___ ___ ___ on the center for length of size. and if player find correct letter ,for example A in text on the first there should be __A__ ____ ____ ____ but on diffferent computer it isnt appear like that it was ____ _____ _____ _____ after click "Sonraki" which mean "next" all of _____ gone.Moreover pictures reload slowly
    any suggestion?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    Hard to know what the problem with your code is without seeing it.

    I've downloaded all the class files and images and will take a look.
    Last edited by Norm; 12-04-2011 at 02:13 AM.

  10. #10
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    thank you,waiting for your post

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    Can you post the code for your inner classes that are listeners for the buttons? My decompiler did not do a good job of creating the source for them.

  12. #12
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    i have sent you with private msg.
    i think problem is occur because MyPanel class isnt working good on html websides.MyPanel class draw _____ and Letter which is found by player like that ___A___

    must i include html to MyPanel class ? it extend by deneme class?
    Last edited by KSBeyaz; 12-04-2011 at 03:21 PM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    You should not load the images every time in the paint method. Move the code to the init() method and do it only once.

    I tried many different method calls to cause the JVM to display the components that you had setVisible(false) and then later tried to setVisible(true). I found that if I called the validate() method for the container that was holding the panel that was holding the component that was just set visible, that they would be shown.

    Java Code:
    	
       		panels[zt] = new MyPanel(txt.charAt(zt));
            	pnl1.add(panels[zt]);
    		panels[zt].setVisible(false);
    Java Code:
            panels[tt].setVisible(true);
            pnl1.validate();  // THIS WORKS  <<<
    Last edited by Norm; 12-04-2011 at 05:01 PM.

  14. #14
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    Quote Originally Posted by Norm View Post
    You should not load the images every time in the paint method. Move the code to the init() method and do it only once.

    I tried many different method calls to cause the JVM to display the components that you had setVisible(false) and then later tried to setVisible(true). I found that if I called the validate() method for the container that was holding the panel that was holding the component that was just set visible, that they would be shown.

    Java Code:
    	
       		panels[zt] = new MyPanel(txt.charAt(zt));
            	pnl1.add(panels[zt]);
    		panels[zt].setVisible(false);
    Java Code:
            panels[tt].setVisible(true);
            pnl1.validate();  // THIS WORKS  <<<
    so if i only add
    Java Code:
    pnl1.validate();  // THIS WORKS  <<<
    it will work?
    i didnt get it clearly.
    may you explain a bit more plz?

    what is validate() for ? what it do ?i see it first time.
    ty

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: How to make image invisible and visible in applet

    it will work?
    Try it and see what happens.

    what is validate() for
    Read the API doc for the Component class.

  16. #16
    KSBeyaz is offline Member
    Join Date
    Nov 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to make image invisible and visible in applet

    it is said that Request that the component and its affected containers be laid out again. You should not generally need to invoke this method unless you explicitly change a component's size/alignment hints after it's visible or change a containment hierarchy after it is visible. Always invoke repaint after revalidate. okey ty for your help will try

Similar Threads

  1. How can I make the graphics visible?
    By AcousticBruce in forum New To Java
    Replies: 9
    Last Post: 03-01-2011, 03:53 AM
  2. Replies: 3
    Last Post: 10-20-2010, 06:24 AM
  3. Replies: 2
    Last Post: 01-30-2010, 05:14 AM
  4. Replies: 2
    Last Post: 04-14-2009, 10:01 PM
  5. How to make the JTextArea background invisible
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2007, 06: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
  •