How to use Radio Button in Java Tutorial using NetBeans IDE

0
81

This tutorial is all about How to use Radio Button in Java Tutorial using NetBeans IDE. In this tutorial you will learn how to insert a value in database using radio button. Radio Button is very useful when it comes to data registration, because radio button can be use in a field of gender or sex. It will help you identify if that person is a he or she. This tutorial uses radio button and NetBeans IDE. Please follow all the steps below to complete this tutorial.

 

How to use Radio Button in Java Tutorial using NetBeans IDE steps

 

The first step is to

Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After creating a project, the default form will be created automatically. and now the next step is to drag two radio buttons in this example I use radio button based on gender.

After dragging the two radio button rename it as Male and the other one is Female.

And then go to your code and create a gender variable, after creating the variable go to your gui and double click each radio button. Like for example when you double click the male radio button you will assign a value to a gender variable to gender=” Male” otherwise its gender=” Female”

 

  1. try {
  2.  
  3. String sql = "INSERT INTO users (first name, last name, gender) VALUES (?,?,?)";
  4.  
  5. pst = conn.prepareStatement(sql);
  6.  
  7. pst.setString(1, fnameTxt.getText());
  8.  
  9. pst.setString(2, lnameTxt.getText());
  10.  
  11. pst.setString(3, gender);
  12.  
  13. pst.execute();
  14.  
  15. JOptionPane.showMessageDialog(null, "User has been added!");
  16.  
  17. }catch(Exception e){
  18.  
  19. JOptionPane.showMessageDialog(null , e);
  20.  
  21. }

 

Then you’re done. Run your project and see if it works.

 

 

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: ryansalem221996@gmail.com

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Simple Restaurant Management System using Java Tutorial
2.) How to use Recursion in Java Tutorial Using Netbeans IDE

 

 

Facebook Comments
(Visited 82 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here