Share on Google+Share on Google+

sunil kumar pandey
java swing
1 Answer(s)      7 years ago
Posted in : Java Beginners
How to set the rang validation on textfield, compare validation textfields , and also if we create a groupbutton like male female, if we want to send the selected item in database , how to send ,
plz help .........
thanx a lot


View Answers

March 10, 2010 at 12:13 PM

Hi Friend,

Try the following 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");
JLabel lbl1 = new JLabel("Name");
final JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Password");
final JPasswordField jt2=new JPasswordField(15);
JLabel lbl3 = new JLabel("Confirm Password");
final JPasswordField jt3=new JPasswordField(15);
JLabel lbl4 = new JLabel("Gender");
final JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
Female=new JRadioButton("Female");
JButton button=new JButton("Submit");
text=new JTextField(15);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=jt1.getText();
String pass=jt2.getText();
String cpass=jt3.getText();
String g=text.getText();
JOptionPane.showMessageDialog(null,"You cannot exceed more than 10 characters in the name field");
else if(!pass.equals(cpass)){
JOptionPane.showMessageDialog(null,"Your password and confirm password does not match");
else if((Male.isSelected()==false)&&(Female.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");

Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("insert into names(name,password,gender) values(?,?,?)");
int i=st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
catch(Exception ex){}

private ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.setText(((JRadioButton) e.getSource()).getText());


Related Tutorials/Questions & Answers:
java swing - Swing AWT
java 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
java swing
java swing  view the book details using swing
Java swing
Java swing  Does Swing contains any heavy weight component
Java swing
Java swing  what are the root classes of all classes in swing
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 Foundation Classes), which is an API for providing a graphical user interface for Java
java swing
java swing  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link: Grid view in java swing Thanks
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: Thanks
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
java swing
java swing  add two integer variables and display the sum of them using java swing
java swing - Swing AWT
java 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 AWT
java 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... a proxy or how to make my java web browser to listen to proxy setting??? please help
JAVA SWING  Hi.... Iam doing project in java...and my front end in swing ..our project is like billing software... then what are the topics i want cover? then how to design? pls help me
java swing.
java swing.  Hi How SetBounds is used in java programs.The values in the setBounds refer to what? ie for example setBounds(30,30,30,30) and in that the four 30's refer to what
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
java swing - Swing AWT
java swing  how to save data in sql 2005 while insert in textfield  Hi Friend, Try the following code: import java.sql.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import
java - Swing AWT
What is Java Swing AWT  What is Java Swing AWT
swing - Java Beginners
Swing application testing  What are the conventions for testing a Java swing application
Java swing
Java swing  how to create simple addition program using java swing?   import java.awt.*; import javax.swing.*; import java.awt.event.*; class SumOfNumbers extends JFrame { SumOfNumbers(){ JLabel lab1=new
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code for the above item   import java.sql.*; import java.awt.*; import javax.swing.
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form on jinternalframe and connect to mysql. import*; import java.sql.*; import java.awt.
Java swing
Java swing  How to combine two java files
java swing
java swing  meaning of out.flush
Java swing
Java swing  What method is used to specify a container's layout
Java swing
Java swing  What methods are used to get and set the text label displayed by a Button object
Java Swing
Java Swing  I want scroll bar in a frame is it possible? if it is possible means i want coding for that please send me a reply
Java Swing
Java Swing   i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the answer sir/madam
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
Java Swing
Java Swing  i have a Label more than that of a frame .... how to extend the frame to view the label which are hidden.. please send me the coding sir/madam
java swing
java swing  iam using my project text box, label , combobox and that the same time i want menubar and popmenu. plz give me code for this. i want immediately plz send me that code
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null