Results 1 to 5 of 5
Thread: radio boxes linking to an image
- 12-13-2011, 12:12 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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 12:23 AM. Reason: code tags added
- 12-13-2011, 01:10 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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?
- 12-13-2011, 03:27 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
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?
- 12-13-2011, 04:14 PM #4
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?
- 12-13-2011, 05:55 PM #5
Re: radio boxes linking to an image
Also see Image display for individual radio button
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Combo Boxes HELP
By nksjolinder1 in forum New To JavaReplies: 8Last Post: 10-25-2011, 05:44 AM -
how can i get an image as a list value of radio button in struts2
By aaruviswa in forum Web FrameworksReplies: 0Last Post: 12-30-2010, 03:55 AM -
Three Different Dialogue Boxes
By lala in forum New To JavaReplies: 7Last Post: 10-29-2010, 07:04 PM -
Dragging Boxes
By anilanar in forum New To JavaReplies: 8Last Post: 09-05-2009, 09:23 PM -
radio and image
By snitdesne in forum New To JavaReplies: 4Last Post: 11-22-2008, 01:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks