instead of text boxe i have to show check box as selected.

Ads
 

instead of text boxe i have to show check box as selected.

i have one text field. in that iam getting boolean value either true or false from the database. when ever the valsue is there in textfield, instead of text boxe i have to show check box as selected.

Thanks In advance R.Raveen.

View Answers

May 17, 2012 at 3:46 PM

The given code retrieves the data from the database table and show values on Frame.

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

class ShowCheckboxSelected extends JFrame
{

ShowCheckboxSelected(){
String des = "Deselected";
String sel = "Selected";

JLabel label1 = new JLabel();
label1.setText("Name:");
JTextField text1 = new JTextField(20);

JLabel label2 = new JLabel();
label2.setText("Age:");
JTextField text2 = new JTextField(20);

JLabel label3 = new JLabel("Indian?");
JCheckBox check = new JCheckBox();


JPanel panel=new JPanel(new GridLayout(3,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(check);
add(panel);

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from employee where id='2'");
        String str=" ";
        if(rs.next()){
            text1.setText(rs.getString("name"));
            text2.setText(Integer.toString(rs.getInt("Age")));
            str=rs.getString("nationality");
            System.out.println(str);
            if(str.equals("true")){
                check.setSelected(true);
            }
            else{
                check.setSelected(false);
            }

        }
    }
catch(Exception e){}

}
public static void main(String arg[]){
try
{
ShowCheckboxSelected frame=new ShowCheckboxSelected();
frame.pack();
frame.setVisible(true);
}
catch(Exception e)
{}
}
}

Ads









Related Tutorials/Questions & Answers:
instead of text boxe i have to show check box as selected.
instead of text boxe i have to show check box as selected.  i have... the database. when ever the valsue is there in textfield, instead of text boxe i have to show check box as selected. Thanks In advance R.Raveen.
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
Dynamically display values in dropdown box and then show the selected values... this code it is adding one more value to the dropdown box and showing as selected. so if I have 5 values in the dropdown this selected one is added as 6th values
Advertisements
Dynamically display values in dropdown box and then show the selected values as selected by the user which is already stored in the DB
in the list box. Somehow I can just show only one as selected but not multiple records...Dynamically display values in dropdown box and then show the selected values..., This is for Updating. I had two SQL queries one for only selected values
approve or reject multiple selected rows using check box
approve or reject multiple selected rows using check box   Select Article Document Type Document Sub Type
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box   i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
how to get selected name from combo box
how to get selected name from combo box  i have fetched all records of worker i.e worker name. on a test.jsp and dispayed it into combo box ...my... of worker name within d combo box and display that id into a text box. plz answer
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
textfield selected text
textfield selected text  How to select text in text field
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile... the result is ok but after getting value of first box now i want a result of second box
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.  I have a tex box. in that i want user should enter data in the format specified(for eg--abcde_)how
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below... code for me jsp file... <%@page contentType="text/html" pageEncoding...;<input type="text" value =" " property= "amount" id='pricecheck'/> <
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below... code for me jsp file... <%@page contentType="text/html" pageEncoding...;<input type="text" value =" " property= "amount" id='pricecheck'/>
Dynamic check box problem
Dynamic check box problem  In my project i have used a dynamic table, in the each row of that table there is one check box [that i have created...='enable_text()' name="check"> <td><input type="text" name="name
show selected date range in calender
show selected date range in calender  helo, i'm working in a project in jsp. suppose thier are 2 textbox 1.start date 2. end date whatever date selected in these textbox get highlighted in the calendar, please help
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
java script text box
in alert). i also want the text box should generate in front of NEW button(next/prev...java script text box  hi, I created a button when i click on button(next/prev) new two textbox is created. i want to do the two textbox will show
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface... is your code, we have modified it. import java.io.*; interface arith { int a=5
HI Jsp check box..!
HI Jsp check box..!  Hi all.. I want to update the multiple values of database table using checkbox..after clicking submit the edited field has to update and rest has to enable to update...please help me..its urgent
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
How to assign a default value to text box in netbeans
How to assign a default value to text box in netbeans  I have a java application,and i want to assign a default variable to the textbox
Drag a Text Box into dynamic positions
Drag a Text Box into dynamic positions  Plz can anyone tell how can i drag a text box using mouse or arrow keys... Im doing a accounts projects and i need this feature for cheque configuration
I have crude application
I have crude application   I have crude application, how to load into this roseindia.net

Ads