Results 1 to 5 of 5
  1. #1
    akahafe is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default radio boxes linking to an image

    Hi Would any one be able to help me with my code?

    I cant seem to link a radio button to an image. Can anyone see what I am doing wrong?

    Java Code:
     
    import java.awt.event.*;       // For event listeners.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.image.*; 
    import javax.imageio.ImageIO;//for testing
    import java.io.*;
    
    public class DisplayPhotosPage extends JDialog implements ActionListener
    {
           
          //*****************************Variables******************************************************//
            private JPanel pnPanelGeneral;      // Holds all controls in it
             
            
            private JLabel lblHeader;
            private JButton btnNext;
            private JButton btnBack;
            private ImagePanel pnImg1, pnImg2, pnImg3, pnImg4, pnImg5, pnImg6, pnImg7, pnImg8, pnImg9, pnImg10;
            private JPanel pn1, pn2, pn3, pn4, pn5, pn6, pn7, pn8, pn9, pn10;
              
        
        /**
         * Constructor
         */
        public DisplayPhotosPage() 
        {
          this.createGUI();
    
        } 
        
        /** Adds all the controls on the GUI
          *
          * @author Mariandi Stylianou
          */
        private void createGUI()
        {
               setTitle( "Image Selection");  // Set the header
               Dimension minSize = new Dimension(700,400);
               this.setMinimumSize(minSize);
               this.setLocation(600,300);
                
               pnPanelGeneral =(JPanel)getContentPane();  
               GridLayout gdPanelExternal = new GridLayout(3,5, 10, 10); 
               pnPanelGeneral.setLayout( gdPanelExternal );
             
               pnPanelGeneral.setBorder( BorderFactory.createTitledBorder( "Please select an image:" ) ); //Adds a titled border to the window
              //  pnPanelGeneral.insets()= new Insets(10,10,10,10) ;       
             
              BufferedImage img = null;
                 
               try{ 
                  // Set the image holder
                   img = ImageIO.read(new File("Photo-0056.jpg"));
                 }
               catch(Exception e)
               {
                  System.out.println(e);
               }
               ImagePanel pnImg1 = new ImagePanel(img);
               pn1 = new JPanel();
               pn1.setLayout( new GridLayout(0,1));
               pn1.add(pnImg1);
               pn1.add(new JRadioButton("Select", true));
               pnPanelGeneral.add(pn1);
             
               ImagePanel pnImg2 = new ImagePanel(img);
               pn2 = new JPanel();
               pn2.setLayout( new GridLayout(0,1));
               pn2.add(pnImg2);
               pn2.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn2);
             
               ImagePanel pnImg3 = new ImagePanel(img);
               pn3 = new JPanel();
               pn3.setLayout( new GridLayout(0,1));
               pn3.add(pnImg3);
               pn3.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn3);
               
               ImagePanel pnImg4 = new ImagePanel(img);
               pn4 = new JPanel();
               pn4.setLayout( new GridLayout(0,1));
               pn4.add(pnImg4);
               pn4.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn4);
               
               ImagePanel pnImg5 = new ImagePanel(img);
               pn5 = new JPanel();
               pn5.setLayout( new GridLayout(0,1));
               pn5.add(pnImg5);
               pn5.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn5);
               
               
               ImagePanel pnImg6 = new ImagePanel(img);
               pn6 = new JPanel();
               pn6.setLayout( new GridLayout(0,1));
               pn6.add(pnImg6);
               pn6.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn6);
                
               ImagePanel pnImg7 = new ImagePanel(img);
               pn7 = new JPanel();
               pn7.setLayout( new GridLayout(0,1));
               pn7.add(pnImg7);
               pn7.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn7);
              
               ImagePanel pnImg8 = new ImagePanel(img);
               pn8 = new JPanel();
               pn8.setLayout( new GridLayout(0,1));
               pn8.add(pnImg8);
               pn8.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn8);
               
               ImagePanel pnImg9 = new ImagePanel(img);
               pn9 = new JPanel();
               pn9.setLayout( new GridLayout(0,1));
               pn9.add(pnImg9);
               pn9.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn9);
               
               ImagePanel pnImg10 = new ImagePanel(img);
               pn10 = new JPanel();
               pn10.setLayout( new GridLayout(0,1));
               pn10.add(pnImg10);
               pn10.add(new JRadioButton("Select", false));
               pnPanelGeneral.add(pn10);                      
                      
               btnBack = new JButton( "Back"  );
               //btnBack.addActionListener(this);
               pnPanelGeneral.add( btnBack );
               
               // add blank space
               pnPanelGeneral.add(new JLabel(""));
               pnPanelGeneral.add(new JLabel(""));
               pnPanelGeneral.add(new JLabel(""));
                         
               btnNext = new JButton( "Next"  );
               //btnNext.addActionListener(this);
               pnPanelGeneral.add( btnNext );
                             
               setDefaultCloseOperation( DISPOSE_ON_CLOSE );
             
               setContentPane( pnPanelGeneral );
               pack();
               setVisible( true );
               
               
        }
        
         / Adds functionality on the buttons of EffectPage
       
        public void actionPerformed(ActionEvent event)
        {
           
    //        if (event.getSource()== btnPrint )
    //         {
    //             //Call print function
    //             pnImg.PrintPanel();
    //             return;
    //         }
    //         else if (event.getSource()==  btnSave)
    //         {   
    //             // Call save function
    //             return;
    //         }
    //         else if (event.getSource()== btnEmail)
    //         {
    //               
    //             // Call Email function
    //             return;
    //         }
    //         else  if (event.getSource()== btnNext)
    //         {
    //             
    //             this.setVisible(false);
    //            
    //             return;
    //         }
    //         else // the only button left here the back button
    //         {
    //             
    //               
    //             this.setVisible(false);
    //             
    //             return;
    //         }
        }
    }
    Last edited by pbrockway2; 12-13-2011 at 01:23 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: radio boxes linking to an image

    <quote>I cant seem to link a radio button to an image.</quote>

    Maybe I'm missing something, but I don't see anything in that code which reacts to radio button clicks. (Or which puts the buttons into a group so they can act as radio buttons). See How to Use Radio Buttons in Oracle's Tutorial.

    Or perhaps you mean something else by "linking" the buttons to the images?

  3. #3
    akahafe is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: radio boxes linking to an image

    Yes you are correct but its the radio box code I am having problems with. Can anyone make any suggestions?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: radio boxes linking to an image

    Can you explain what a "radio box" is?
    Where is the code you are having problems with?
    What is the problem you are having?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: radio boxes linking to an image

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Combo Boxes HELP
    By nksjolinder1 in forum New To Java
    Replies: 8
    Last Post: 10-25-2011, 06:44 AM
  2. Replies: 0
    Last Post: 12-30-2010, 04:55 AM
  3. Three Different Dialogue Boxes
    By lala in forum New To Java
    Replies: 7
    Last Post: 10-29-2010, 08:04 PM
  4. Dragging Boxes
    By anilanar in forum New To Java
    Replies: 8
    Last Post: 09-05-2009, 10:23 PM
  5. radio and image
    By snitdesne in forum New To Java
    Replies: 4
    Last Post: 11-22-2008, 02:41 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
  •