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: .setVisible() troubles

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default .setVisible() troubles

    Hi,
    im trying to make a simple program that sets on image visible when you click a button, and then the other one on when you click it again. This is what i have so far:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JComponent;
     
    import java.awt.Toolkit;
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class DinoYesNo {
     
        public static void main(String[] args) {
            GridLayout myLayout = new GridLayout(2, 1);
            JFrame frame = new JFrame( "Yes No Dino");
            frame.setSize(400,200);        
            JPanel myPanel = new JPanel();
            myPanel.setLayout(myLayout);
     
            //make GIF icons
            final ImageIcon dinoyes = new ImageIcon("S:\\dinoyes.gif");
            final ImageIcon dinono = new ImageIcon("S:\\dinono.gif");
     
            //make switcher button
           final JButton switcher = new JButton ("Yes/No"); 
     
      ActionListener al = new ActionListener(){
       public void actionPerformed(ActionEvent e){
          int check = 0;
          if (check == 0){
              dinoyes.setVisible(true);
              dinono.setVisible(false);
              check++;
       }
     
       else{
           dinoyes.setVisible(false);
           dinono.setVisible(true);
           check--;
    }
    }
    };
     
            switcher.addActionListener(al);
            switcher.setToolTipText("Switches yes and no");
            myPanel.add(dinoyes);
            myPanel.add(dinono);
            myPanel.add(newButton);
            frame.getContentPane().add(myPanel);
            frame.setVisible(true);
     
     
        }
    }

    it is giving me an error with "dinoyes.setVisible(true);" it says "cannot find symbol - method setVisible(boolean)"

    any advice?
    Joel


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: .setVisible() troubles

    See the API for ImageIcon - there is no setVisible method. Try placing the ImageIcon in a JLabel...I recommend reading the following: How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  3. The Following User Says Thank You to copeg For This Useful Post:

    KevinWorkman (October 4th, 2011)

  4. #3
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: .setVisible() troubles

    Hey, thanks for the help I got it to work. I changed my if statement as well so that it was if "(label.isVisible())" Thanks

Similar Threads

  1. array troubles
    By mike2452 in forum Collections and Generics
    Replies: 3
    Last Post: August 14th, 2011, 07:22 PM
  2. Instantiation troubles
    By hello_world in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 16th, 2011, 08:24 PM
  3. ArrayList troubles
    By javapenguin in forum What's Wrong With My Code?
    Replies: 20
    Last Post: November 18th, 2010, 06:03 PM
  4. JSP Troubles
    By sdkeslar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 12th, 2010, 02:26 PM
  5. Array Troubles
    By Leeds_Champion in forum Collections and Generics
    Replies: 6
    Last Post: October 22nd, 2009, 11:05 AM