Results 1 to 4 of 4

Thread: JAVA GUI stuff

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    JAVA GUI stuff

    1. on radiobuttons:

    JRadioButton a= new JRadioButton("A");
    JRadioButton b= new JRadioButton("B");
    ButtonGroup bg = new ButtonGroup();
    bg.add(a); bg.add(b);
    JPanel mode = new JPanel(new GridLayout(1, 1));
    mode.add(bg);

    ERROR:
    Incompatible type for method. Can't convert javax.swing.ButtonGroup to java.awt.Component.

    eh?

    2. also, how do i use the isSelected method so that radiobutton "A" is selected on load?

    3. finally, x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); in void main, but it doesn't work, something like EXIT_ON_CLOSE not declared...

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    mode.add(a); mode.add(b);

    The ButtonGroup is a manager, it isn't added to anything.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: JAVA GUI stuff

    Originally posted by quipy
    3. finally, x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); in void main, but it doesn't work, something like EXIT_ON_CLOSE not declared...
    I remember hitting this bug when I was in school. Try this instead :
    Code:
    x.addWindowListener(new WindowAdapter()
    {
        public void windowClosing(WindowEvent we) { System.exit(0); }
    });
    Where x is the JFrame as you have indicated.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372

    Re: JAVA GUI stuff

    Originally posted by quipy

    2. also, how do i use the isSelected method so that radiobutton "A" is selected on load?
    Use a.setSelected(true) in the form constructor

    3. finally, x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); in void main, but it doesn't work, something like EXIT_ON_CLOSE not declared...
    You need JDK 1.4 for that. You can also use 3 but that didn't always work in the lower versions. Your best bet is the windowadapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width