Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2008, 08:46 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Reacting Radio button event
Code:
import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; public class RadioButtonTest extends JFrame implements ActionListener { JLabel label = new JLabel("The quick brown fox jumps over the lazy dog."); private JRadioButton smallButton; private JRadioButton mediumButton; private JRadioButton largeButton; private JRadioButton xlargeButton; public RadioButtonTest() { setTitle("RadioButtonTest"); setSize(400, 200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JPanel buttonPanel = new JPanel(); ButtonGroup group = new ButtonGroup(); smallButton = addRadioButton(buttonPanel, group, "Small", false); mediumButton = addRadioButton(buttonPanel, group, "Medium", true); largeButton = addRadioButton(buttonPanel, group, "Large", false); xlargeButton = addRadioButton(buttonPanel, group, "Extra large", false); getContentPane().add(buttonPanel, "South"); getContentPane().add(label, "Center"); } public JRadioButton addRadioButton(JPanel buttonPanel, ButtonGroup g, String buttonName, boolean v) { JRadioButton button = new JRadioButton(buttonName, v); button.addActionListener(this); g.add(button); buttonPanel.add(button); return button; } public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == smallButton) label.setFont(new Font("SansSerif", Font.PLAIN, 8)); else if (source == mediumButton) label.setFont(new Font("SansSerif", Font.PLAIN, 12)); else if (source == largeButton) label.setFont(new Font("SansSerif", Font.PLAIN, 14)); else if (source == xlargeButton) label.setFont(new Font("SansSerif", Font.PLAIN, 18)); } public static void main(String[] args) { JFrame frame = new RadioButtonTest(); frame.show(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Radio button AJG New To Java 0 04-07-2008 09:37 PM
Swing - catching click button event Java Tip Java Tips 0 03-12-2008 12:03 AM
AWT - catching click button event Java Tip Java Tips 0 03-12-2008 12:02 AM
How to perform some event to button click eva AWT / Swing 2 01-16-2008 01:27 AM
Radio button values are not lose chockalingam JavaServer Pages (JSP) and JSTL 0 12-03-2007 09:14 AM


All times are GMT +3. The time now is 02:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org