button to accept user input

button to accept user input

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){ public string name,lastname,radiobutton,spinner;

name=JTextfield.getTextfield(); lastname=JTextfield.getTextfield(); show(new Studentinfoview(this)); connectDB(); } i cant figure how i am going to declare the radiobutton and spinner.The user input does not show on my Studentinfo.mdb database it just gives me an error.please help

View Answers

September 18, 2012 at 3:08 PM

Here is java swing example that accepts firstname, lastname and gender from user and insert to database.

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingExample{
JTextField text;

public static void main(String[] args) throws Exception{
SwingExample sf=new SwingExample();
}

public SwingExample(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("First Name");
final JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Last Name");
final JPasswordField jt2=new JPasswordField(15);
JLabel lbl3 = new JLabel("Gender");
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);
lbl3.setBounds(50,130,70,30);
button.setBounds(50,170,100,30);
jt1.setBounds(110,50,100,30);
jt2.setBounds(110,90,100,30);
Male.setBounds(110,130,100,30);
Female.setBounds(210,130,100,30);
text.setBounds(110,170,100,30);
text.setVisible(false);

button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String fname=jt1.getText();
String lname=jt2.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 data(firstname,lastname,gender) values(?,?,?)");
st.setString(1,fname);
st.setString(2,lname);
st.setString(3,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(lbl3);
f.add(jt1);
f.add(jt2);
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:
button to accept user input
button to accept user input  private void jButton1ActionPerformed... the radiobutton and spinner.The user input does not show on my Studentinfo.mdb... that accepts firstname, lastname and gender from user and insert to database
accept integer from user
accept integer from user  Write an Java application that accepts 100 integer numbers from a user. The input should be in the range of 1-200. Error message needs to be displayed if user entered input which is not in this range
Advertisements
Accept command in Oracle
 ACCEPT User input ACC[EPT] variable [NUM[BER]|CHAR|DATE] [FORMAT format... command in SQL Plus. The ACCEPT command in SQL Plus is used to take the input from... how to use the Accept in SQLPlus.ADS_TO_REPLACE_2 SQL> select * from user
escaping user input in php
escaping user input in php  Is it possible to escape the user input while submitting data into database in PHP
JSP view detail page on accept button click
JSP view detail page on accept button click  i Have 1 jsp page in that there r 2 button accept and view details when we click on aceept button it will submit to next page and when click on view details page it will shown the data
Java User Input
Java User Input  I am using Scanner class for user Input. Scanner s = new Scanner(System.in); String name = s.next(); but i am unable to store full name in name variable...how i can store full name plsss reply   use
user input to database
user input to database  /* * Studentinfo2App.java */ package studentinfo2; import java.sql.Connection; import java.sql.DriverManager; import... in my database user input from my applet does not show
user input to database
user input to database  /* * Studentinfo2App.java */ package studentinfo2; import java.sql.Connection; import java.sql.DriverManager; import... in my database user input from my applet does not show
user input to database
user input to database  /* * Studentinfo2App.java */ package studentinfo2; import java.sql.Connection; import java.sql.DriverManager; import... in my database user input from my applet does not show
calculation after if. user input
user input????   My apologies good evening peoples Once again I am...calculation after if. user input  System.out.print ("please select...[]args){ Scanner input=new Scanner(System.in); System.out.print
user input in java - Java Beginners
user input in java   i am trying to write a code to compute the average of 5 numbers but i dont know what to do for the program to accept user input  Hi import java.util.*; public class AverageExample { public
How to read user input in C++
How to read user input in C++  How can i get an input from the users in C++?   You can use the standard input "cin" to get the input from user.. For example: int age; cin >> age
How to take input by user using jDialogue and use that input
How to take input by user using jDialogue and use that input  I am using NetBeans i have a 'Search by employee id' button . I want when user click this button a dialogue box appear which take employee_id as input from user
XP Bowling Game User input help
XP Bowling Game User input help  I was asked to do the XP Bowling Example as an assignment. I have the programme passing all tests, but now I need to make the code accept input from a user and display the scores/frames
java user input - Java Beginners
java user input  how to input from keyboard? please give a example.  Hi Friend, There are lot of ways to input data from keyboard.You...:****** try{ System.out.print("Enter String:"); BufferedReader input = new
error in taking input from user.
error in taking input from user.  //i m having problem inputting the array from user.my program is import java.io.*; class bubble { public static void main(String args[]) { int a[]=new int[20]; int i=0; BufferedReader br=new
Java get User Input
Java get User Input       In this section, you will learn how to get the user input from... that will communicate with the user at the command line and returns the user input. We have
accept sentence from user and print all word starts with vowel and end with consonent
accept sentence from user and print all word starts with vowel and end with consonent  Write a program to accept a sentence. Print all the words that starts with vowel and end with a consonant. e.g. input by user "the purpose
Create a input button inside js function
Create a input button inside js function  I call my js function from HTML code from another file. Now I would like to create a input button on page.... Now I would like to create a input button on page using createElement() in my
Design a registration.jsp page with input for user registration details
Design a registration.jsp page with input for user registration details  Design a registration.jsp page with input for user registration details like firstname, lastname, choose username, choose password, confirm password. After
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening the program. I am developing a college library management system, i would like
Write a program that takes the marks of user as input
Write a program that takes the marks of user as input  Write a program that takes the marks of user as input. If marks are greater then 60 the program should display "Great, you have passed the course", else the program should
Managing Multiple User Input Data in an Array (or ArrayList)
Managing Multiple User Input Data in an Array (or ArrayList)  Hey... record alphabetically (2) If user chooses choice1, the input data is stored in an ARRAY (or ARRAYLIST) until the user chooses to stop inputting data. Kindly
Display PHP clock with user input date and time
Display PHP clock with user input date and time  The following PHP code displays a clock with current date and time. I want the clock to receive user input date and time. How can this be done? <?php date<em>
Radio Button in HTML
Radio Button in HTML is a type of input form that allows a user to select one button from a group of button. When a user clicks on a radio button, it becomes checked, while all other button remains unchecked. <input type>
Read user input in Java using Scanner
Example of of reading user input in Java using Scanner In this section we... input from console. Our sample program asks user to enter name and then age, user input is read using the scanner class. Information entered by user is printed
Getting ISD code when user input country name
Getting ISD code when user input country name  I want to create program which user needs by typing Country name he will get ISD code of that country... code, from that list i have to read the file and when user input any country name
input
input  a java program that will exchange the last names of two students that were input by a user
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below..."><label> <input name="radiobutton" type="radio" value...;<input type="hidden" name="hidden"><font color="white" size="5"><
Simple input application in Echo3
an application which contains the window from where the user can  input a text and this value would be shown into the content pane when user will click... Simple input application in Echo3   
forwarding request to a jsp when user clicks on back button in ie
forwarding request to a jsp when user clicks on back button in ie  Hi all, I have developed a web based application. After user log out... we forward request to a jsp page whenever user clicks on back button
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble sorts and selections sorts  I can get both of the sorts figured out but i... how many elements are going to be input by the user?   Here is a code
Submit comments in database when user clicks on submit button
Submit comments in database when user clicks on submit button... database when user clicks the submit button of the page. Create a database: First create a database named "usermaster" in MySql and table named "user
Servlet Error Message based on user input
Servlet Error Message based on user input   ... to check the user input against database and display the message to the user. This example illustrate how to ensure that user input is correct by validating
Accept Language and Accept Char set in Servlets
sends the user's language to the server using the Accept Language HTTP header.... It is an estimate of the user preference for the language. Default value of q-value is 1.0 which is (maximum). Now the Accept Language Header with q-value
ModuleNotFoundError: No module named 'accept'
ModuleNotFoundError: No module named 'accept'  Hi, My Python... 'accept' How to remove the ModuleNotFoundError: No module named 'accept'... to install padas library. You can install accept python with following command
How to prevent from navigating to ck buttonnext page when user reaches login page using back button
goback to user login page using back button and agin click browser forward button,the 2nd page session gets expired but on next click on forward button,the pdf...How to prevent from navigating to ck buttonnext page when user reaches login
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page  I am using wysiwyg editor... by the user and also can be saved to his location in word document format. Can
Array and input
[ ]={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; i want to ask user to input one of the above numbers then i want to print the array without the number user input. how will i do tht
JSP Back Button
;       Jsp Back Button enables the user back... button and displayed in text area. The Back button takes the user back to the page they just came from. A Back button is created by INPUT type="
Can ArrayList accept an ImageIcon >>????
Can ArrayList accept an ImageIcon >>????  haw can create ArrayList witch can accept Image ..mean when i use add() method, instead item let me add image to the ArrayList in run time .{should be the program using GUI
Button
Button  How to use image for button in JSF
can Stack accept imageIcon ..??
can Stack accept imageIcon ..??  how can write program like album ..by using Stack as an ideas datastracture and using imageIconb ?? please help me ..thanks alot
keyboard input
keyboard input  how do I use JOptionPane to accept keyboard input? I know how to import but not specific command on input line   import javax.swing.*; class JOPtionPaneExample { public static void main(String
javascript focus input
the user and a submit button. This button calls the function setfocus() which checks whether user has entered some value to the input boxes one by one. If any one...;<br> <input type="button" id="name" onClick="setfocus()" value="Submit
the App Store does not accept or distribute web apps
the App Store does not accept or distribute web apps  the App Store does not accept or distribute web apps We found the user interface of your app is not of sufficient quality to be appropriate for the App Store What could

Ads