Results 1 to 5 of 5

Thread: radio and image

  1. #1
    snitdesne is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default radio and image

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    
    
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    
    import java.awt.event.*;
    
    
    
    public class CarRentalGUI extends JFrame implements ListSelectionListener, ActionListener{
        
        private final static int FRAME_WIDTH = 300;  // Application window width
        private final static int FRAME_HEIGHT = 300; // Application window height
        private final static int SCREEN_OFFSET = 100; // Placement of application window on screen
        private final static String TITLE = "Car Rental";
        private final static int RIGID_AREA_HEIGHT=20;
       
        
        
        // RADIO BUTTONS
        JRadioButton radioAll   = new JRadioButton("All"  , true);
       
        JRadioButton radioCompact  = new JRadioButton("C: Compact"   , false);
        JRadioButton radioMidsize = new JRadioButton("M: Midsize", false);
        JRadioButton  radioLarge   = new JRadioButton("L: Large"  , false);
        JRadioButton radioFun  = new JRadioButton("F: Fun"   , false);
        JRadioButton radioSUV = new JRadioButton("S: SUV", false);
        
        //radio panel   
         JPanel radioPanel = new JPanel();
       
         //avalible scrollpane
        private DefaultListModel availableList;
    	private JList availableJList;
    	private JScrollPane availableScroll;
        private final static String numberAvailable="Number of available cars= ";
        private final static JLabel lblAvailableCars = new JLabel(numberAvailable);
        private String numberAvailableValue="";
    	private JButton btnReserveSelected= new JButton("Reserve Selected");
    	private final static JPanel pnlAvailable = new JPanel();
        
       private void setUpAvailablePane() {
    		
           
    		availableList=new DefaultListModel();
    		availableJList=new JList(availableList);
    		availableScroll=new JScrollPane(availableJList);
    		availableJList.setFont(new Font("Courier", Font.PLAIN, 12));
    		availableJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    	    availableJList.addListSelectionListener(this);
    		availableScroll.setAlignmentX(Component.CENTER_ALIGNMENT);
    		availableScroll.setPreferredSize(new Dimension(250, 100));
    		for(int i=0; i<40; i++){
    		//	mylist.addElement(ss[i]);
    		    availableList.addElement(i);
             }
    	}
    
        private void setUpRadio(){
       
            ButtonGroup groupRadio = new ButtonGroup();
            groupRadio.add(radioAll);
            groupRadio.add(radioCompact);
            groupRadio.add(radioMidsize);
            groupRadio.add(radioLarge);
            groupRadio.add(radioFun);
            groupRadio.add(radioSUV);
           
    
            radioPanel.setLayout(new GridLayout(6, 1));
            radioPanel.add(radioAll);
            radioPanel.add(radioCompact);
            radioPanel.add(radioMidsize);
            radioPanel.add(radioLarge);
            radioPanel.add(radioFun);
            radioPanel.add(radioSUV);
       
            
        }
        private void setUpPanel(){
    		pnlAvailable.setLayout(new BoxLayout( pnlAvailable, BoxLayout.Y_AXIS));
    		pnlAvailable.add(lblAvailableCars);
    		btnReserveSelected.addActionListener(this);
    		pnlAvailable.add(btnReserveSelected);
    	    pnlAvailable.add(Box.createRigidArea(new Dimension(0,RIGID_AREA_HEIGHT)));
    	    
    	}
       public void valueChanged(ListSelectionEvent e) {}
    
        public void run(){
            
            
            setUpRadio();
            setUpAvailablePane();
            setUpPanel();
            
            Container c = getContentPane();
            c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
            c.add(radioPanel);
            c.add( pnlAvailable );
           
           
            pack();
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        }
        
        
        
        
        public static void main(String args[]){
            CarRentalGUI crg=new CarRentalGUI();
            crg.run();
        }
    
        // @Override
        public void actionPerformed(ActionEvent e) {
            
                  
        }
    }

    first off i was wondering if anyone could tell me why my scroll bar is not having the items 1-40 and then how do i get an image of a car next to the radio button that changes when a radio button is selected

    thx for all help
    snitde

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I cannot see that you have added the scroll bar into the panel, did you?

    And also please keep in mind that ask your question next time more specifically. I don't think no one likes to run your too long code and see what happen. If you can post only the code segment where you stuck others can really helpful to help you. If later they want to see more in your code, you can post the too. :)

  3. #3
    snitdesne is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default

    yea thx i forgot to add to the panel. how would i go about adding a picture next to the radio buttons that changes when a diffrent button is selected

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Help with <html:radio> tag
    By tsaswathy in forum Web Frameworks
    Replies: 0
    Last Post: 09-29-2008, 11:16 AM
  2. How to use Radio Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:26 PM
  3. How to use SWT Radio Button
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM
  4. radio buttons and paint
    By gtraylo in forum Java Applets
    Replies: 1
    Last Post: 04-19-2008, 12:43 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 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
  •