Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Applet button to accept user input
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Thembekile
button to accept user input
1 Answer(s)      2 years and a month ago
Posted in : Applet


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


Advertisement
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
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
Accept command in Oracle
command in SQL Plus. The ACCEPT command in SQL Plus is used to take the input from... User input ACC[EPT] variable [NUM[BER]|CHAR|DATE] [FORMAT format] [DEFAULT... the Accept in SQLPlus. SQL> select * from user where username='&user_name
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
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
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
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 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
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>
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
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
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>
how to pass input from radio button to jsp page
how to pass input from radio button to jsp page  hi.. the code below...; <input name="radiobutton" type="radio" value="radiobutton" /> </label></td> <td width="350"><input type
input
input  a java program that will exchange the last names of two students that were input by a user
Advertisements
 

 

 

DMCA.com