Results 1 to 5 of 5

Thread: 3 Questions

  1. #1
    hiranya is offline Member
    Join Date
    Jun 2007
    Location
    Colombo, Sri Lanka
    Posts
    32
    Rep Power
    0

    Default 3 Questions

    Hi All,

    I got three questions this time.

    1. I have two strings both containing date values (of the form yyyy-mm-dd). How do I compare these two dates and pick the earlier date?

    2. I have a JTextField with a fairly large width (large enough to accommodate multiple lines of text). When the user types in a lengthy string of text it should appear in multiple lines in the text field. How do I achieve this behaviour? (Now when the user types in a long string it all goes into one line and the user has to scroll sideways to see the entire line)

    3. Is there an easier way to bind a JTable to a table in a database?

    Regards,
    Hiranya

  2. #2
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Default

    1. u can compare them like any normal int value by using the > and < sign as long as they are still in the date form(not string, int)

    2. u got to use
    Java Code:
    JTextArea myTextArea = new JTextArea();
    JScrollPane jsp = new JScrollPane(myTextArea);
    this is a light component this way u got to implement a line wrap on it or u can go for the heavier component

    Java Code:
    JTextPane myTextPane = new JTextPane();
    JScrollPane jsp = new JScrollPane(myTextPane);
    this is the heavier component, u don't have to implement a line wrap on it but if u want to customize it and stuff this is the one u want to go for
    add ur jsp to ur frame not ur myTextArea/myTextPane like how u do with ur JTextfield
    i suggest u try both and know whats the different

    3. to bind? well i don't know about what u mean but im guessing to load data from database to JTable? u got to specify each column what field u want to field it up with from ur database
    Last edited by unhurt; 11-12-2007 at 07:29 AM.

  3. #3
    hiranya is offline Member
    Join Date
    Jun 2007
    Location
    Colombo, Sri Lanka
    Posts
    32
    Rep Power
    0

    Default

    Thanks for the help...
    Regarding the third question, for the moment I'm reading the table contents from the database into a multidimensional array and then use the array as the data source of the JTable. Is this the correct way of doing this? If not how?

  4. #4
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Default

    well u can cut the part of adding into the multidimensional array by doing this
    but i don't know how u access ur database, my way is through the
    JDBC-ODBC

    Java Code:
    Ps = Con.prepareStatement(SSQL);
    Rs = Ps.executeQuery();
    
    while(Rs.next()) {
    	dataModel.addRow(new Object[]{(Rs.getString("name")),
    				(Rs.getString("studentID")),
    				(Rs.getString("courseID"))});
    }
    ofcourse it must also include some try catch line, so i explain abit here... prepare the SQL statement then execute it... so while loop will go through the database record till no more found
    datamodel is for the JTable new object will declare new record being append to the end so name, studentID, courseID are my database field name it will get the record from there and will fill up ur JTable bcz of the while loop

    the code above is incomplete, i didn't include my declaration of my JDBC and variable declaration so if u know how to do then i think u know where to put it, else ill give u the complete 1 when u ask for...

  5. #5
    unhurt is offline Member
    Join Date
    Oct 2007
    Posts
    21
    Rep Power
    0

    Default

    hey im sory about part 1.... kinda thought that it would work since it work for me in VB.NET but anyway here is the right one i think u can try


    Java Code:
        Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
        
        Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);
        
        // Determine which is earlier
        boolean b = xmas.after(newyears);            // false
        b = xmas.before(newyears);                   // true
    this is from Comparing Dates (Java Developers Almanac Example)


    for ur part 1, u need to make it string to date format... there is a thread on this here but the output gives me some weird number after the date. come to worse... change all to int lol... and arrange them to be compare by year-month-day(20071131 > 20061131) format lol, i know its kinda incorrect.... but anyway i think for proper format is the simpledateformat, do post ur solution when u found out how... i want to know too ^^....
    Last edited by unhurt; 11-14-2007 at 06:04 AM.

Similar Threads

  1. Stuck on Two Questions, Please Help
    By sylo18 in forum New To Java
    Replies: 5
    Last Post: 03-11-2008, 02:03 AM
  2. 2 simple java questions
    By jimJohnson in forum New To Java
    Replies: 2
    Last Post: 02-02-2008, 10:35 AM
  3. Just a Few Questions
    By pringle in forum New To Java
    Replies: 21
    Last Post: 01-09-2008, 07:21 PM
  4. questions
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-28-2007, 12:18 AM

Posting Permissions

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