Source Code Cross Referenced for RadioButtonDemo.java in  » Web-Framework » webonswing » examples » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » webonswing » examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //WebOnSwing - Web Application Framework
002:        //Copyright (C) 2003 Fernando Damian Petrola
003:        //	
004:        //This library is free software; you can redistribute it and/or
005:        //modify it under the terms of the GNU Lesser General Public
006:        //License as published by the Free Software Foundation; either
007:        //version 2.1 of the License, or (at your option) any later version.
008:        //	
009:        //This library is distributed in the hope that it will be useful,
010:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:        //Lesser General Public License for more details.
013:        //	
014:        //You should have received a copy of the GNU Lesser General Public
015:        //License along with this library; if not, write to the Free Software
016:        //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:
018:        package examples;
019:
020:        import java.awt.*;
021:        import java.awt.event.*;
022:
023:        import javax.swing.*;
024:
025:        public class RadioButtonDemo extends JFrame {
026:            public static void main(String s[]) {
027:                JFrame frame = new RadioButtonDemo();
028:                frame.addWindowListener(new WindowAdapter() {
029:                    public void windowClosing(WindowEvent e) {
030:                        System.exit(0);
031:                    }
032:                });
033:
034:                frame.pack();
035:                frame.setVisible(true);
036:            }
037:
038:            public RadioButtonDemo() {
039:                setContentPane(new RadioButtonDemoPanel());
040:            }
041:
042:            public static class RadioButtonDemoPanel extends JPanel {
043:                static String birdString = "Bird";
044:                static String catString = "Cat";
045:                static String dogString = "Dog";
046:                static String rabbitString = "Rabbit";
047:                static String pigString = "Pig";
048:
049:                JLabel picture;
050:
051:                public RadioButtonDemoPanel() {
052:                    // Create the radio buttons.
053:                    JRadioButton birdButton = new JRadioButton(birdString);
054:                    birdButton.setMnemonic(KeyEvent.VK_B);
055:                    birdButton.setActionCommand(birdString);
056:                    birdButton.setSelected(true);
057:
058:                    JRadioButton catButton = new JRadioButton(catString);
059:                    catButton.setMnemonic(KeyEvent.VK_C);
060:                    catButton.setActionCommand(catString);
061:
062:                    JRadioButton dogButton = new JRadioButton(dogString);
063:                    dogButton.setMnemonic(KeyEvent.VK_D);
064:                    dogButton.setActionCommand(dogString);
065:
066:                    JRadioButton rabbitButton = new JRadioButton(rabbitString);
067:                    rabbitButton.setMnemonic(KeyEvent.VK_R);
068:                    rabbitButton.setActionCommand(rabbitString);
069:
070:                    JRadioButton pigButton = new JRadioButton(pigString);
071:                    pigButton.setMnemonic(KeyEvent.VK_P);
072:                    pigButton.setActionCommand(pigString);
073:
074:                    // Group the radio buttons.
075:                    ButtonGroup group = new ButtonGroup();
076:                    group.add(birdButton);
077:                    group.add(catButton);
078:                    group.add(dogButton);
079:                    group.add(rabbitButton);
080:                    group.add(pigButton);
081:
082:                    // Register a listener for the radio buttons.
083:                    RadioListener myListener = new RadioListener();
084:                    birdButton.addActionListener(myListener);
085:                    catButton.addActionListener(myListener);
086:                    dogButton.addActionListener(myListener);
087:                    rabbitButton.addActionListener(myListener);
088:                    pigButton.addActionListener(myListener);
089:
090:                    // Set up the picture label
091:                    picture = new JLabel(new ImageIcon("resources/images/"
092:                            + birdString + ".gif"));
093:
094:                    // The preferred size is hard-coded to be the width of the
095:                    // widest image and the height of the tallest image.
096:                    // A real program would compute this.
097:                    picture.setPreferredSize(new Dimension(177, 122));
098:
099:                    // Put the radio buttons in a column in a panel
100:                    JPanel radioPanel = new JPanel();
101:                    radioPanel.setLayout(new GridLayout(0, 1));
102:                    radioPanel.add(birdButton);
103:                    radioPanel.add(catButton);
104:                    radioPanel.add(dogButton);
105:                    radioPanel.add(rabbitButton);
106:                    radioPanel.add(pigButton);
107:
108:                    setLayout(new BorderLayout());
109:                    add(radioPanel, BorderLayout.WEST);
110:                    add(picture, BorderLayout.CENTER);
111:                    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
112:                }
113:
114:                /** Listens to the radio buttons. */
115:                class RadioListener implements  ActionListener {
116:                    public void actionPerformed(ActionEvent e) {
117:                        picture.setIcon(new ImageIcon("resources/images/"
118:                                + e.getActionCommand() + ".gif"));
119:                    }
120:                }
121:
122:            }
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.