Home Answers Viewqa Java-Beginners Swing programming

 
 


Ragavan
Swing programming
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners

import javax.swing.*;
import java.awt.*;
public class SwingFrame
{
public static void main(String[] args) throws Exception
{
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Age");
JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");
JPanel jp=new JPanel();
JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
jp.add(Male);
radioGroup.add(Male);
Female=new JRadioButton("Female");
jp.add(Female);
radioGroup.add(Female);
JLabel lbl4=new JLabel("Branch");
JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
lbl1.setBounds(100,120,70,30);
lbl2.setBounds(100,240,70,30);
lbl3.setBounds(100,340,70,30);
lbl4.setBounds(100,420,70,30);
jt1.setBounds(170,120,100,40);
jt2.setBounds(170,230,100,40);
jp.setBounds(170,340,100,40);
jc.setBounds(170,420,100,40);
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(lbl4);
f.add(jt1);
f.add(jt2);
f.add(jc);
f.add(jp);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
This is the program i typed. If I run this program, the radiobutton should not work properly. Please someone help me.
View Answers

February 1, 2010 at 3:46 PM


Hi Friend,

We have modified your code,try it:

import javax.swing.*;
import java.awt.*;
public class SwingFrame
{
public static void main(String[] args) throws Exception
{
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Age");
JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");
JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JLabel lbl4=new JLabel("Branch");
JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
lbl1.setBounds(100,120,70,30);
lbl2.setBounds(100,240,70,30);
lbl3.setBounds(100,340,70,30);
lbl4.setBounds(100,420,70,30);
jt1.setBounds(170,120,100,40);
jt2.setBounds(170,230,100,40);
Male.setBounds(170,340,100,40);
Female.setBounds(270,340,100,40);
jc.setBounds(170,420,100,40);
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(lbl4);
f.add(jt1);
f.add(jt2);
f.add(jc);
f.add(Male);
f.add(Female);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Thanks









Related Pages:
Swing programming - Java Beginners
Swing programming  import javax.swing.*; import java.awt.*; public... { JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane... in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1 = new JLabel
game programming code - Swing AWT
game programming code  write a snake program using swings with step by step explanation?. please send me this source code to my mail id with step by step explanation
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java... the following link: Swing Tutorials
Java Swing
("Pascal"); JLabel lab=new JLabel("Enter Programming Language: "); final
Swing - Java Beginners
Swing  Hi friends. I need a swing programming book for free download... links: http://www.grandt.com/sbe/ http://www.javafaq.nu/java/free-swing-book... can also visit the following link where you can find lot of swing examples
Need Help with Java-SWING progrmming - Swing AWT
Need Help with Java-SWING progrmming  Hi sir, I am a beginner in java-swing programming. I want to know how we can use the print option with a program in swing. Could you help me with an example? Regards Sreejith 
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
Media Player - Swing AWT
Media Player  Hi All, Could u help me? How can i create new media player in java programming language
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
java programming - Java Beginners
the following links: http://www.roseindia.net/java/example/java/swing/add_edit_and_delete_employee_inf.shtml http://www.roseindia.net/java/example/java/swing
java programming - Java Beginners
links: http://www.roseindia.net/java/example/java/swing/add_edit_and_delete_employee_inf.shtml http://www.roseindia.net/java/example/java/swing/Print.shtml
How to Hide Button using Java Swing
Programming application how to hide the buttons using Java Swing. Please Visit this below reference link http://www.roseindia.net/tutorial/java/swing... programming. How to hide the button in Java programming. Please anyone suggest
Java Swing Tutorials
Java Swing Tutorials       Java Swing tutorials -  Here you will find many Java Swing... and you can use it in your program. Java Swing tutorials first gives you brief
Programming
Programming  Given a number n, write a programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
Java Graphics Programming
IT?   The given code draws a line and a rectangle on a swing frame using
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Java Programming: Chapter 7 Index
to Swing. Although the title of the chapter is "Advanced GUI Programming... Chapter 7 Advanced GUI Programming IT'S POSSIBLE TO PROGRAM A WIDE... routines covered in that chapter suffice. But the Swing graphical user interface
event-driven programming paradigm of Java. - Java Beginners
event-driven programming paradigm of Java.  Design a scientific calculator using event-driven programming paradigm of Java.  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java/swing
Java Programming: Section 6.1
that is essential for programming applets, the init() method. This method... and Swing The AWT (Abstract Windowing Toolkit) has been part of Java from... are generally not as complex as full-scale, independent applications. The Swing
Java Programming: Section 1.6
in the original version of Java. The other, which is known as Swing... Swing instead of the AWT. If you see the above applet but just see a blank area... the details for now, but try to get some feel about how object-oriented programming
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program. This program requires passing arrays as parameters and returning arrays from methods.../java/example/java/swing/ Thanks
Java Programming: Preface to the Fourth Edition
programming. Swing has more features and is more sophisticated. I have rewritten all the GUI programming examples to use Swing, and I have extensively rewritten the parts of the book that cover GUI programming. Because Swing is so complex
Java Programming: Section 10.5
Section 10.5 Threads and Network Programming NETWORK PROGRAMS...;7.6 in the context of GUI programming. (If you have not already read... programming and about threads. To address the first problem with the command
Java Programming: Section 3.7
TWO CHAPTERS, you've been learning the sort of programming that is done inside..., before moving on to programming-in-the-large, we'll take a look at how programming-in-the-small can be used in other contexts besides text-based, command-line