How to save Selected text of RadioButton in to Access Databse
Sir I wnt To store Selected JRadioButton Text in to access Database
plz Help Me Sir.
and how to link website in to our Java Application with JRadioButton.
View Answers
March 20, 2010 at 11:38 AM
Hi Friend,
To insert JRadioButton text, you need to create a textfield which should be invisible on the frame. This textfield will get the selected radio button value using ActionListener.
Here is the code:
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingFrame{
JTextField text;
public static void main(String[] args) throws Exception{
SwingFrame sf=new SwingFrame();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
final JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Gender");
text=new JTextField(15);
final JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JButton button=new JButton("Submit");
text=new JTextField(15);
Male.addActionListener(al);
Female.addActionListener(al);
lbl1.setBounds(50,50,70,30);
lbl2.setBounds(50,90,70,30);
button.setBounds(50,130,100,30);
jt1.setBounds(110,50,100,30);
Male.setBounds(110,90,100,30);
Female.setBounds(210,90,100,30);
text.setBounds(110,130,100,30);
text.setVisible(false);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=jt1.getText();
String g=text.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("insert into names(name,gender) values(?,?)");
st.setString(1,name);
st.setString(2,g);
int i=st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
}
catch(Exception ex){}
}
});
f.add(lbl1);
f.add(lbl2);
f.add(jt1);
f.add(Male);
f.add(Female);
f.add(button);
f.add(text);
f.setSize(500,500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText(((JRadioButton) e.getSource()).getText());
}
};
}
Related Tutorials/Questions & Answers:
Advertisements
selected radiobutton to display different pageselected radiobutton to display different page there are three radio button are there , in that
selected button to display different page. when submit it, using struts2 framework .
plz help me to
how write code
radiobuttonradiobutton
how to add
radiobutton in combobox in java
Text field save as word fileText field
save as word file Dear experts At run
how to
save set of
text field contains
text into single Word file. To
save in our desktop computer. Solve my problem
Save JRadioButton Text in to database - Java BeginnersSave JRadioButton
Text in to database Hello Sir I have Two JaradioButtons
1)Semwise Course
2)Yearwise Course
I want To
Save Text from JRadioBuuton in to
Access Databse
and
Access Databse. with user can select any one
save text file - Java Beginnerssave text file hi
i have just start programming in java.please guide me if i want to read a
text file in java.then the
text file is
save in which directory
Javascript get Date And Selected Option Text to get the
selected option
text and displayed
in Javascript.
This tutorial explains you that
how to display the date and the
selected
option
text in Javascript...Javascript get Date And
Selected Option
Text
In this tutorial we will learn
save output in multiple text filessave output in multiple
text files Hi..I'm getting problem to store the output of this php code into multiple
text files. Can anyone sugeest.
Here is my code:
<?php
for($i=1; $i<=100; $i++)
{
$html = file_get
RadioButton in Flex4RadioButton in Flex4:
In Flex4
RadioButton is a spark component. You can use two or more
RadioButton
components with in a RadioButtonGroup and select only one
RadioButton at one
time and if one stands in
selected mode then all
RadioButton Control in FlexRadioButton Control in Flex:
The
RadioButton control in Flex is a set... member of this group can be
selected at a time. We can not select more than one radio button at a
time.
<mx:RadioButton> tag is used to
access how to insert data from netbeans into databsehow to insert data from netbeans into databse
how to insert data from netbeans into
databse
Please visit the following link:
http://www.roseindia.net/webservices/web-services-database.shtml
Radiobutton in XcodeRadiobutton in Xcode I am new to Xcode .I want to implement
Radiobutton in Xcode (using Objective C),and when i select any
Radiobutton ,it should remain
selected when i open my view next time.
Is it possible anyway ? Any advise
How to Display values from databse into tableHow to Display values from
databse into table I want to display values from database into table based on condition in query,
how to display...;b>Authors Name</b></td>
<td>: <input type="
text" name
How to Access MS Access in jar.How to
Access MS
Access in jar.
how do i
access my Ms-
Access file... to
access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to
access a Ms-
access via JDBC but cant find the file wen
radiobutton - JDBCradiobutton hi
how do you insert a
radiobutton into a table.
eg:
how to select army and put it into a column in JDBC.
army is a part of the the group
army
navy
air force
How to save value in JSPHow to
save value in JSP Employee Name Time-IN Time-OUT... 324 2012-12-12
save
i want to
save dis value jsp to action ...
how can i get all value ..and store..
how can its values goes
how can i print the selected content of a framehow can i print the
selected content of a frame hello sir, I am... to skip all the
text fields shapes and all the button from the frame.. but all the values of
text fields and levels should be there.. please send me any
how to get selected name from combo box how to get
selected name from combo box i have fetched all records... of worker name within d combo box and display that id into a
text box.
plz answer me this
q. urgently.
With Regards,
Vishwnath
how to get selected name from combo box how to get
selected name from combo box i have fetched all records... of worker name within d combo box and display that id into a
text box.
plz answer me this
q. urgently.
With Regards,
Vishwnath
how to get selected name from combo boxhow to get
selected name from combo box i have fetched all records... of worker name within d combo box and display that id into a
text box.
plz answer me this
q. urgently.
With Regards,
Vishwnath
how to get selected name from combo boxhow to get
selected name from combo box i have fetched all records... of worker name within d combo box and display that id into a
text box.
plz answer me this
q. urgently.
With Regards,
Vishwnath
how to get selected name from combo boxhow to get
selected name from combo box i have fetched all records... of worker name within d combo box and display that id into a
text box.
plz answer me this
q. urgently.
With Regards,
Vishwnath
How to access Subclass?How to
access Subclass?
How to
access subclass in java? please tell me the syntex with an example
How to save file in vi editor?How to
save file in vi editor? Hi,
I am trying to find commands... the commands?
Thanks
Hi,
Here are the details:
How to
save file... :w to
save the file
Type :wq to
save and quit
Type :
q! to quit without saving
How to save image on the server by appletHow to
save image on the server by applet HI, in my project I am... If user want to export this chart as GIF format then this chart should be
save as a gif image on the server directory. Can any Body help me
how can I do it
Thanks
How to save image on the server by appletHow to
save image on the server by applet HI, in my project I am... If user want to export this chart as GIF format then this chart should be
save as a gif image on the server directory. Can any Body help me
how can I do it
Thanks
How to save data - Swing AWTHow to
save data Hi,
I have a problem about
how to
save data ,but
first before data
save to dababase, data must view in jLisit or Jtable...
save data from jList and Jtable(in jList or jTable data will be many).Thank's