Results 1 to 2 of 2
  1. #1
    anuragsingh is offline Member
    Join Date
    May 2013
    Location
    New Delhi
    Posts
    1
    Rep Power
    0

    Smile Using Thread and JFrame

    I want to make a program in which a jframe is used and in the frame only a textbox exist.

    The function is :-
    1) Pickup the data in the database (Here I used a thread to call the method).
    2) Show the data in the textbox.
    3) Then, Thread goes to sleep mode for some time.
    4) When Thread awake it pick another row from database and show it in textfield.
    5) It continues until database end.

    HERE I PASTE THE CODE IN WHICH HAVE ERROR PLEASE HELP ME TO SOLVE THESE ERROR....
    I USE NETBEANS 7.2 WITH DERBY DATABASE.





    package Desktop_project_pkg;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import javax.swing.*;
    import java.sql.*;

    /**
    *
    * @author AnuragSingh
    */

    public class Remember extends Thread {



    @Override
    public void run ()
    {
    for(int i=1;i<=32;i++)
    {
    try {
    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/Password_db", "ankit", "singh");
    Statement stmt = con.createStatement();
    String sql = "select * from password_table where id=" + i ;
    ResultSet rs = stmt.executeQuery(sql);
    rs.next();

    int id_col = rs.getInt("id");
    String first_name = rs.getString("website"); //capitle and small both are right.
    String last_name = rs.getString("username");
    String job = rs.getString("password");

    String p = id_col + " " + first_name + " " + last_name + " " + job;
    System.out.println(p);
    Thread.sleep(1000);
    }
    catch(SQLException | InterruptedException ex)
    {
    System.out.println("Error:" + ex);
    }
    }

    }
    public static void main(String args[])
    {
    my_Class mf = new my_Class();
    mf.setVisible(true);
    Thread t = new Thread();
    t.start();


    }

    }
    class my_Class extends JFrame {

    my_Class()
    {
    Container contentPane;
    setTitle("Anurag Singh's Reminder.");
    setSize(500, 200);
    contentPane = getContentPane();
    contentPane.setBackground(Color.YELLOW);
    contentPane.setLayout(new FlowLayout(FlowLayout.CENTER));
    contentPane.add(new JLabel("Welcome To Reminder"));
    contentPane.add(new JTextField(10));
    // setSize(80,80);

    //contentPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    // contentPane.add(new JButton("button 1"));

    // contentPane.add(new JButton("Click me please"));
    setLocation(850,10);

    }
    }




    AnyOne Can Help Me Please.....
    Anurag Singh

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Using Thread and JFrame

    When posting code please wrap it in [code] tags [/code] to retain its formatting.

    You ask for help an error, but you haven't actually said what the error is.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Thread painting - simple game - Blank JFrame
    By rru96 in forum New To Java
    Replies: 11
    Last Post: 02-02-2013, 07:47 PM
  2. Click in JFrame Titlebar sets the JFrame Opaque
    By tim8w in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2013, 07:29 AM
  3. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  4. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •