SakthiPrabhu.g
Hi .Again me..
2 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners

View Answers

December 19, 2008 at 4:12 AM


Hi friend,


import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;

public class SRadioButtonDemo{

public static void main(String args[]){

JFrame frame = new JFrame("Button Group");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(0, 1));
Border border = BorderFactory.createTitledBorder("Examples");
panel.setBorder(border);
ButtonGroup group = new ButtonGroup();
AbstractButton abstract1 = new JToggleButton("Toggle Button");
panel.add(abstract1);
group.add(abstract1);
JRadioButton rbutton = new JRadioButton("Radio Button");
panel.add(rbutton);
group.add(rbutton);
JCheckBox chekbox = new JCheckBox("Check Box");
panel.add(chekbox);
group.add(chekbox);
AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item");
panel.add(abstract4);
group.add(abstract4);
AbstractButton jcheckmenu = new JCheckBoxMenuItem("Check Box Menu Item");
panel.add(jcheckmenu);
group.add(jcheckmenu);
Container contentPane = frame.getContentPane();
contentPane.add(panel, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}

--------------------------------------------------------

Visit for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.

December 19, 2008 at 5:42 AM


I am sending running code according to your requirement. Please implement following code.

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;



public class RadioButtonDemo extends JPanel implements ActionListener {
static String birdString = "Rose";
static String catString = "Cat";
static String dogString = "Dog";
static String tigerString = "Tiger";
static String undoString = "Undo";

JLabel picture;

public RadioButtonDemo() {
super(new BorderLayout());

//Create the radio buttons.
JRadioButton birdButton = new JRadioButton(birdString);
birdButton.setMnemonic(KeyEvent.VK_B);
birdButton.setActionCommand(birdString);
birdButton.setSelected(true);

JRadioButton catButton = new JRadioButton(catString);
catButton.setMnemonic(KeyEvent.VK_C);
catButton.setActionCommand(catString);

JRadioButton dogButton = new JRadioButton(dogString);
dogButton.setMnemonic(KeyEvent.VK_D);
dogButton.setActionCommand(dogString);

JRadioButton rabbitButton = new JRadioButton(tigerString);
rabbitButton.setMnemonic(KeyEvent.VK_R);
rabbitButton.setActionCommand(tigerString);

JRadioButton pigButton = new JRadioButton(undoString);
pigButton.setMnemonic(KeyEvent.VK_P);
pigButton.setActionCommand(undoString);

//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(birdButton);
group.add(catButton);
group.add(dogButton);
group.add(rabbitButton);
group.add(pigButton);

//Register a listener for the radio buttons.
birdButton.addActionListener(this);
catButton.addActionListener(this);
dogButton.addActionListener(this);
rabbitButton.addActionListener(this);
pigButton.addActionListener(this);

//Set up the picture label.
picture = new JLabel(createImageIcon("images/" + birdString + ".gif"));


picture.setPreferredSize(new Dimension(177, 122));

//Put the radio buttons in a column in a panel.
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
radioPanel.add(birdButton);
radioPanel.add(catButton);
radioPanel.add(dogButton);
radioPanel.add(rabbitButton);
radioPanel.add(pigButton);

add(radioPanel, BorderLayout.LINE_START);
add(picture, BorderLayout.CENTER);
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

// Listens to the radio buttons
public void actionPerformed(ActionEvent e) {
picture.setIcon(createImageIcon("images/" + e.getActionCommand() + ".gif"));
}

// Returns an ImageIcon, or null if the path was invalid
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = RadioButtonDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
JFrame frame = new JFrame("RadioButtonDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
JComponent newContentPane = new RadioButtonDemo();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);

frame.setSize(300,250);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
---------------------------
Thanks.









Related Pages:
Hi .Again me.. - Java Beginners
Hi .Again me..  Hi Friend...... can u pls send me some code on JPanel.. JPanel shoul have 1pic 1RadioButton .. Like a Voter List... REsponse me..  Hi friend, import java.io.*; import java.awt.
hi again - Java Beginners
hi again  i did the changes on the code but still the time is not decreasing i wanna reach increasing running time target sorry for asking too...; // testing every character for (int n=0 ;n  Hi friend, Do changes
again with xml - XML
again with xml  hi all i am a beginner in xml so pls give me the details regarding the methods used in it. wat will return the methods.../content.aspx?b=STY_XML_21days&seqNum=207 Thanks Rajanikant  Hi
again java - Java Beginners
.i need it pls help me.  Hi Friend, Have you got any error...again java  i will ask iam using servlets ,in one program my requirement is if there is a image(if u like) in anywhere and we browse that image
again java - Java Beginners
again java  Hi, i will ask iam using servlets ,in one program my requirement is if there is a image(if u like) in anywhere and we browse... please tell me step by step procedure. pls help me.   Hi Friend
JFREE error again
JFREE error again  hi......... As i had asked u the jfree error i want to tel u that i have taken the both the jar files jfree and jcommon. but then also its giving me error i am able to compile the code but now when i am
Hi..Again Doubt .. - Java Beginners
Hi..Again Doubt ..  Thank u for ur Very Good Response...Really great.. i have completed that.. If i click the RadioButton,,ActionListenr should get... WORRY WE'ILL ROCK "); } } }   Hi Can u send your MainMenu.java
Read data again - Java Beginners
Read data again  sir, i still hav a problem,first your code will be change like this : in netbeans out message error 5. Can you help me again. My... System.err.println("Error: " + e.getMessage()); }  Hi friend
doesnt run again - Java Beginners
the soltion   Hi I am sending u again the code, this code run in my...doesnt run again  the code u sent doesnt run and the error msg says illegal start with do even if i change it it keeps telling me the same
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It is displayed and it is not going to next level. HTTP Status 404 - /struts/hello type
HI.
HI.  hi,plz send me the code for me using search button bind the data from data base in dropdownlist
Hi
Hi  Hi How to implement I18N concept in struts 1.3? Please reply to me
hi....
hi....  plzz sent me d code for counting vowels in a string... gui programme
Hi
Hi  I want import txt fayl java.please say me...   Hi, Please clarify your problem! Thanks
hi
hi  My program is not find java.io.File; why? help me please
Hi
Hi  Hi All, I am new to roseindia. I want to learn struts. I do not know anything in struts. What exactly is struts and where do we use it. Please help me. Thanks in advance. Regards, Deepak
hi
, again the label with ââ?¬Å?+Click to add another accountââ?¬Â? should be enable
Hi
Hi   I have got this code but am not totally understanding what the errors. Could someone Please help. Thanks in advance! import java.util.Random...!"); // this says to guess higher System.out.print("Wrong! Again Guess
hi
, display the menu again. the user should respond to this prompt with another
hi
online multiple choice examination  hi i am developing online multiple choice examination for that i want to store questions,four options,correct answer in a xml file using jsp or java?can any one help me?   Please
hi.......
for such a programme... plz help me...   Hi Friend, Try this: import java.awt....hi.......  i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design
hi
for such a programme... plz help me... i hope for a speedy reply from ur side
hi
for such a programme... plz help me... i hope for a speedy reply from ur side
Hi
Hi  The thing is I tried this by seeing this code itself.But I;m facing a problem with the code.Please help me in solving me the issue. HTTP Status 500 - type Exception report message description The server encountered
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi..
hi..   I want upload the image using jsp. When i browse the file... BRwowse File!!twad9315.jpg show me BROWSE FILE...); System.out.println("show me"); // Pattern String browsefile
hi
hi   i want to develop a online bit by bit examination process as part of my project in this i am stuck at how to store multiple choice questions... can any one help me??????   We are providing you a simple application
hi
storing data in xml file using jsp  hi i am storing data in xml file using jsp.in this when i enter data into xml file i am getting xml declaration for each specified data?can any one help me to prevent this?   <
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html...); System.out.println("show me"); // Pattern String browsefile= browsefile1.replace
help again plz sorry - Java Beginners
help again plz sorry  Thanks for giving me thread code but i have a question this code is comletelly right and i want to make it runs much faster...; onescounter=0; // testing every character for (int n=0 ;n  Hi
Plz chk it and reply again - Java Beginners
Plz chk it and reply again  Hi Deepak, Thanks for fast... will be slow also. so plz help me for this if u understood my question then plz fast reply.  Hi Ragini, Please specify your requirements
After Logout Back Button Should not work again
Kindly Help me... your regards, Prudvi raj.   Hi, you would might...After Logout Back Button Should not work again  Hi deepak,, I am doing Login Page,.. IN That If Logout Then When I Click Logout Button It Should
hi frnds.. help me..
hi frnds.. help me..  i ve a doubt in incompatible type error (block letter). plz help me clear this error! thanks in advance. This is my code. double velo[][] = new double [task] [resource]; for(int i=0;iList<Double>
java again - Date Calendar
java again  I can't combine your source code yesterday, can you help me again. My problem is how we get result jtextfield2 from if jtexfield1 we enter(jTextfield keypressed) then the result out to jTextfield2, This my jFrame
when refreshing the page the data is stored in data base again
when refreshing the page the data is stored in data base again  Hi, In my application, I am adding form data in database on click of submit... body give me good link for this problem... Thanks a lot
matching database again - Java Beginners
this ask a question page again. Thank God. I want to say "A BIG THANK YOU" for helping me about the matching codes. It is working now after fine tuning the SQL query :-) but I can't do it without you showing me the steps. My question
Reply Me - Java Beginners
Reply Me  Hi, This is not correct url please send me again coorect url
Read data again - Java Beginners
Read data again  Hey, i want to ask again about how to read data from txt, My DB: kd_div varchar(15), nm_div varchar(30), dep varchar(25... data from txt file and send to DB.i'm using one button to call.  Hi
Reply Me - Java Beginners
"code too large for try statement" please help me its very urgent......   Hi Ragini, I can understand your problem. Today once again try...Reply Me  Hi Amardeep I am sending database table name,code
Reply Me - Java Beginners
Reply Me  Hi deepak, your sending web application is good... will be not displayed. please help me how it is open selection of the user its very urgent Thanks Ragini   Hi Ragini Actually, you can not direct access

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.