Swing programming
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 Tutorials/Questions & Answers:
Swing programming - Java BeginnersSwing 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 AWTgame
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
Advertisements
SWINGSWING A JAVA CODE OF MOVING TRAIN IN
SWING swingswing How to make
swing component auto-resizable when JFrame resize
swingswing Write a java
swing program to delete a selected record from a table
SwingSwing 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
SwingSwing 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
ProgrammingProgramming 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
What is Swing?What is
Swing? What is Java
Swing? Where to get the tutorials of
Swing? I am beginner in Java
Swing programming and trying to find the tutorials of
Swing.
Tell me the urls to learn
swing.
Thanks
Hi,
Swing is Java
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 swingjava 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 - Swing AWTjava swing how i can insert multiple cive me exampleolumn and row in one JList in
swing?plz g Hi Friend,
Please clarify your question.
Thanks
swing-awt - Swing AWTswing-awt Hi,
Thanks for replying to my question...I'm getting some confusion to add action events in my application(Rich Text Editor).How to add action events?
Thank U
swing/awt - Swing AWTswing/awt How to create richtexteditor using swings...?I'm very much new to swings....It's urgent.....Thank u...
hello
read this book you get idea;
JFC
Swing Tutorial, The: A Guide to Constructing GUIs, Second
Swing paint - Swing AWTSwing paint hi,
i want to print something on window using
swing applet..
m doing dis..
protected void paintComponent(Graphics g... the
Swing Applet, use html file with the following code:
Java Applet Demo
swing smsswing sms HOW TO SEND SMS MESSAGE FROM
SWING USING SQL DATABASE
Swing ProgramSwing Program Write a java
swing program to calculate the age from given date of birth
SWING FRMESSWING FRMES hai SIR?
HOW TO DESIGN
swing Frames
send source code
SWING FRMESSWING FRMES hai SIR?
HOW TO DESIGN
swing Frames
send source code
swing to appletswing to applet hi how i can isplay a java
swing into applet java
thanks
java swing - Swing AWTjava
swing how i can insert in JFrame in
swing? Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class FormDemo extends JFrame {
JButton ADD;
JPanel
java swing - Swing AWTjava swing how to add image in JPanel in
Swing? Hi Friend,
Try the following code:
import java.awt.*;
import java.awt.image....:
http://www.roseindia.net/java/example/java/
swing/
Thanks
Swing - Java BeginnersSwing 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
Java swingJava swing what are the root classes of all classes in
swing Java swingJava swing Does
Swing contains any heavy weight component
AWT & SWINGAWT & SWING What is diffennce between AWT &
SWING java swingjava swing view the book details using
swing Jva swing Jva
swing How to create the model form like "Notepad
swing programswing program Write a java
swing program to getname and email id. Display the message if email id contains the name of theuser
SWING - Swing AWTSWING how can i insert image in Jpanel by extending class with JFrame in
swing? Hi Friend,
Try the following code:
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import
java swing - Swing AWTjava
swing Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy servers through which i should visit any web site.So, i want my browser also
swing - Swing AWTswing how to create JTabbedPane.when i choose one jtabbedpane it will appear JTextField,resultMessages.pls give me any examples Hi Friend,
Try the following code:
import javax.swing.*;
import java.awt.
SWING - Swing AWTSWING how to insert image and components such as JLabel,JButton,JTextfield in JFrame in
swing? Hi Friend,
Try the following code:
import java.io.*;
import java.awt.*;
import javax.swing.*;
import
Swing question - Swing AWTSwing question I want to move a string in JFrame similarily as done by marquee tag in HTML.The string should move from right to left. How can I do this? Hi Friend,
Try the following code:
import java.awt.
Swing applicationSwing application Hello, I want to develop a
Swing application similar to J2EE application.The only difference is that, the users will access the application not through web browsers, instead through a
Swing desktop application
java swingjava swing how to connect database with in grid view in java
swing
Hi Friend,
Please visit the following link:ADS_TO_REPLACE_1
Grid view in java
swing
Thanks
Swing ProgramSwing Program write a java
swing program to get user name and password. The name contains only characters while password is masked with the character "*". Apply checks for all validation
Swing ProgramSwing Program Write a java
swing program that takes name and marks as input with all validation. The name and marks will be displayed in message box when user clicks on a button
swing with jdbc - Swing AWTswing with jdbc Hi, i m developing the desktop application using swing.i want to use table structure for that.also its DB specific application. i have some problems with
swing using jdbc.
1. the values entered in table
java swingjava swing add two integer variables and display the sum of them using java
swing Swing EJBSwing EJB Hi everyone !!!
I tried to find wether EJB architecture can operate
with
swing, because I am trying to make application
which would work as with
swing client side, instead
jsp or other web page page(s).
I wondered
Java swingJava swing Write a java
swing program to calculate the age from given date of birth
swing questionswing question how to write multiple line text area in a single frame