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



Home Answers Viewqa Java-Beginners how to convert java fram to java servlets
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vincent mon
how to convert java fram to java servlets
0 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


hi every java master or java professional can you teach me how to convert JFram to Java Servlets program hope yours can reply me Thank you. below this is my own coding

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

 public class AddressBook extends JFrame implements ActionListener{
    public void frame(){
    AddressBook panel = new AddressBook();
    panel.setSize(330,350);
    panel.setVisible(true);
    panel.setResizable(false);
    panel.setLocation(330,200);

    }

    JLabel lblId = new JLabel("ID Number : ",JLabel.RIGHT);
    JLabel lblFName = new JLabel("First Name : ",JLabel.RIGHT);
    JLabel lblAddress = new JLabel("Address : ",JLabel.RIGHT);
    JLabel lblLName = new JLabel("Last Name : ",JLabel.RIGHT);
    JLabel lblPNumber = new JLabel("Phone :  ",JLabel.RIGHT);

    JTextField txtId = new JTextField(20);
    JTextField txtFName= new JTextField(20);
    JTextField txtAddress= new JTextField(20);
    JTextField txtLName = new JTextField(20);
    JTextField txtPNumber = new JTextField(20);

    JButton btnNew = new JButton(new ImageIcon("news.jpg"));
    JButton btnUpdate = new JButton(new ImageIcon("update.jpg"));
    JButton btnDelete = new JButton(new ImageIcon("delete.jpg"));
    JButton btnSearch = new JButton(new ImageIcon("search.jpg"));

    Connection cn;
    Statement st;
    PreparedStatement ps;

    public void clear(){

        txtId.setText("");
        txtFName.setText("");
        txtAddress.setText("");
        txtLName.setText("");
        txtPNumber.setText("");
    }


    public AddressBook() {
        super("MY Electronic Address Book Application ");

        JPanel pane = new JPanel();
        pane.setLayout(null);
        pane.setBackground(Color.pink);

        lblId.setBounds(5,50,80,25);
        pane.add(lblId);
        txtId.setBounds(90,50,150,25);
        pane.add(txtId);

        lblFName.setBounds(5,85,80,25);
        pane.add(lblFName);
        txtFName.setBounds(90,85,150,25);
        pane.add(txtFName);

        lblLName.setBounds(5,120,80,25);
        pane.add(lblLName);
        txtLName.setBounds(90,120,150,25);
        pane.add(txtLName);

        lblPNumber.setBounds(5,155,80,25);
        pane.add(lblPNumber);
        txtPNumber.setBounds(90,155,150,25);
        pane.add(txtPNumber);

        lblAddress.setBounds(5,190,80,25);
        pane.add(lblAddress);
        txtAddress.setBounds(90,190,150,25);
        pane.add(txtAddress);

        btnNew.addActionListener(this);
        btnNew.setBounds(5,255,75,35);
        btnNew.setBackground(Color.white);
        pane.add(btnNew);

        btnNew.addActionListener(this);
        btnUpdate.setBounds(80,255,75,35);
        btnUpdate.setBackground(Color.white);
        pane.add(btnUpdate);

        btnUpdate.addActionListener(this);
        btnDelete.setBounds(155,255,75,35);
        btnDelete.setBackground(Color.white);
        pane.add(btnDelete);

        btnDelete.addActionListener(this);
        btnSearch.setBounds(230,255,75,35);
        btnSearch.setBackground(Color.white);
        pane.add(btnSearch);

        btnSearch.addActionListener(this);
        setContentPane(pane);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pane.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(), " Personal Information"));

        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            cn = DriverManager.getConnection("jdbc:odbc:AddressBook ");
        }catch(ClassNotFoundException e)  {
            System.err.println("Failed to load driver");
            e.printStackTrace();
        }catch(SQLException e){
            System.err.println("Unable to connect");
            e.printStackTrace();}
        }

        public void actionPerformed(ActionEvent e){

            Object source = e.getSource();

        if(source == btnNew){
            try{
            st= cn.createStatement();
                ps=cn.prepareStatement("INSERT INTO PInfo " + " (IDN,FName,LName,PNumber,Address) " + " VALUES(?,?,?,?,?)");
            ps.setString(1,txtId.getText());
                ps.setString(2,txtFName.getText());
                ps.setString(3,txtLName.getText());
                ps.setString(4,txtPNumber.getText());
                ps.setString(5,txtAddress.getText());
                ps.executeUpdate();
                JOptionPane.showMessageDialog(null,"New record has been successfully added.","Suspect sample program",JOptionPane.INFORMATION_MESSAGE);
                txtId.requestFocus(true);
                st.close();
                clear();

                }catch(SQLException sqlEx){
                System.out.println(sqlEx.getMessage());}}

            if(source == btnSearch){
                try{
                st= cn.createStatement();
                    int id=0;
                    String search;
                    clear();
                    search=JOptionPane.showInputDialog(null,"Search Id Number","Find What?",JOptionPane.PLAIN_MESSAGE);
                    ResultSet rs=st.executeQuery("SELECT * FROM PInfo WHERE IDN = '" + search + "'");
                        while(rs.next()){
                            txtId.setText(rs.getString(1));
                            txtFName.setText(rs.getString(2));
                            txtLName.setText(rs.getString(3));
                            txtPNumber.setText(rs.getString(4));
                            txtAddress.setText(rs.getString(5));
                            id=Integer.parseInt(rs.getString(1));
                            }
                        if(id==0){
                            JOptionPane.showMessageDialog(null,"No record found!.","Suspect sample program",JOptionPane.ERROR_MESSAGE);
                            clear();
                            txtId.requestFocus(true);
                        }st.close();
                }catch(SQLException s){}}

            if(source == btnUpdate){
                try{
                st= cn.createStatement();
                ps = cn.prepareStatement("UPDATE PInfo SET IDN = '" + txtId.getText() + "',FName = '" + txtFName.getText() + "',LName = '" + txtLName.getText() + "',PNumber = '" + txtPNumber.getText() + "',Address = '"+ txtAddress.getText() + "'WHERE IDN = '" + txtId.getText() + "'");
                ps.executeUpdate();
                JOptionPane.showMessageDialog(null,"record has been successfully updated.","Suspect sample program",JOptionPane.INFORMATION_MESSAGE);
                txtId.requestFocus(true);
                clear();
                st.close();
                }catch (Exception y){
                    y.printStackTrace();}}

            if(source==btnDelete){
                try{
                    ps = cn.prepareStatement("DELETE FROM PInfo WHERE IDN ='"+ txtId.getText() + "'");
                    ps.executeUpdate();
                    JOptionPane.showMessageDialog(null,"record has been successfully deleted.","Suspect sample program",JOptionPane.INFORMATION_MESSAGE);
                    txtId.requestFocus(true);
                    clear();
                    st.close();
                    }catch(SQLException s){
                    System.out.print("SQL statement is not executed!");}
                    catch(Exception j){
                    j.printStackTrace();
                }
            }

       }
 public static void main(String[] args) {
        AddressBook s1=new AddressBook();
        s1.setSize(330,350);
        s1.setLocation(330,200);
        s1.setResizable(true);
        s1.setVisible(true);
    }

 }

Advertisement
View Answers

Related Tutorials/Questions & Answers:
how to convert java fram to java servlets
how to convert java fram to java servlets   hi every java master or java professional can you teach me how to convert JFram to Java Servlets program hope yours can reply me Thank you. below this is my own coding import
How to convert into to String in Java?
How to convert into to String in Java?  Hi, How to convert into to String in Java? Thanks
Advertisements
How to convert string to byte in Java
How to convert string to byte in Java  How to convert string to byte in Java
how to convert string to image in java
how to convert string to image in java  how to convert string to image in java? I know we need to convert image to a byte array at some point in my application but do not know how to convert a image into byte string. Please
java servlets
java servlets  please help... how to connect java servlets with mysql i am using apache tomcat 5.5
how to convert Visual c++ to java - Java Beginners
how to convert Visual c++ to java  Hi Sakthi here.. How to convert Visual c++ codings to Java codings.. Does both have any similarity in library files
How to convert http website into Https from java?
How to convert http website into Https from java?  could any one tell me how to convert http website into Https from java
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
how to convert time in milliseconds in to hours - Java Beginners
how to convert time in milliseconds in to hours  hello, can anyone tell me how i can convert the time in milliseconds into hours or to display it in seconds in java
how to convert time in milliseconds in to hours - Java Beginners
how to convert time in milliseconds in to hours  hello, can anyone tell me how i can convert the time in milliseconds into hours or to display it in seconds in java
How to convert Arraylist into String Array Java
How to convert Arraylist into String Array Java  Hi, I am beginners of Java programming. Can somebody Suggest me how to convert arraylist to string... information with example. You can find the online example of how to convert arraylist
How to Convert PDF into rtf File Java
How to Convert PDF into rtf File Java  Hi, How could in covert the PDF file to rtf file in Java Programming. Please suggest any online example... the online example of Java Convert PDF into rtf File. Thanks
How to convert long to hexadecimal - Java Beginners
How to convert long to hexadecimal  Dear all, anyone know how to convert long data to hexadecimal, please send me the information. Thanks .../java/java-conversion/HexadecimalToBinaryAndLong.shtml Thanks
Java Servlets
Java Servlets  If the binary data is posted by both doGet and doPost then which one is efficient?Please give me some example by using both doGet and doPost. Thanks in Advance   The doPost method is more efficient
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...); } i want to convert the data from inputStream into Zip Stream and so
servlets - Java Beginners
to respond to HTTP requests. A JSP layered on top of Java Servlets. Whereas...servlets  what is the difference b/w servlets and JSP, what servlets engine DO? why we convert jsp to servlet engine code in web server?  
How to convert java BigDecimal to normal byte array not 2 s complement
How to convert java BigDecimal to normal byte array not 2 s complement  How to convert java BigDecimal to normal byte array not 2 s complement
how to convert java Applet to Jave Frame
how to convert java Applet to Jave Frame  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to convert Java Applet to Jave Frame below this code is my applet source code
how to convert doc file into html using java swing
how to convert doc file into html using java swing  i want to convert doc file into html and display it on jtextarea please help me and give the sample code
GUI and how to convert a distance - Java Beginners
GUI and how to convert a distance  i need help.. how to create a GUI application that can be is used to convert a distance unit in miles into its... JLabel("In Inches"); l5=new JLabel("In CM"); b=new JButton("Convert
java servlets - Java Beginners
java servlets  hai my question is on xml documentation in creation of a java servlets. whether we have to create for each and every servelet we have to create each xml documentation?   Hi friends Exactly what you
How to export web page to excel using java or jsp or servlets
errors. Please can anyone tell me how to do this using java or jsp or servlets...How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am
How to convert excel file int xml format in java
How to convert excel file int xml format in java  How to read excel file(xls) which is stored in any directory(D://) and convert it into xml format in java and place in any directory(E://).Can any body provide the code
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
Use Java Bean In Servlets
Use Java Bean In Servlets In this you will learn how to use Java Bean in Servlets. For this purpose, we have created a Bean named 'Person' and defined three variables with their setters and getters. Then we have created an object
how to convert text file to xml file in java. - XML
how to convert text file to xml file in java.  Hi all, I m having some problem. Problem is I want to convert a text file which is having the no of record(i.e no of different line of information)to a xml file through java
How to Convert SOAP Web service to REST Web service In Java ?
How to Convert SOAP Web service to REST Web service In Java ?  I want to Convert SOAP Web service(WSDL) to REST web service in JSON Format with GET...,and Jersey is a tool for REST. Please tell me how to convert SOAP web service
How to convert EBCDIC format value into ASCII format value in java
How to convert EBCDIC format value into ASCII format value in java  how to convert EBCDIC data format into ASCII format data using java Use Case:I... to convert EBCDIC data value into ASCII data values. Please help me to solve
servlets - Java Beginners
servlets   I am doing small project in java on servlets. I want to generate reports on webpage ,how is it possible and what is the difference between dynamic pages & reports ? tell me very urgent pls,pls
Servlets - Java Beginners
Servlets  Hi, How can i run the servlet programon my system? I wrote the code in java.(I've taken the Helloworld program as example program... for this web.xml file? How to run this program?  Hi friend
java servlets - Java Beginners
java servlets  i want to close window when ever he logout from one page... this closing is done with yes/no option. when ever press "yes" it means he successfully logout from page. if press "no" it means he not logout from
Advertisements
 

 

 

DMCA.com