Results 1 to 5 of 5
  1. #1
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Help with Table and code structure.

    I have two classes at the moment, main and gui. The gui class creates a frame that allows users to enter a code, and the return button should open up a table with the information gained from the internet. The main class at the moment just creates a gui object.

    So currently I just have the window. The next thing I need to do is make a table appear when the return button is clicked. Can someone explain how to make a table and do I make it in another class? Also how do I create an action listener such that the table pops up?

    thanks

  2. #2
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Help with Table and code structure.

    bump

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with Table and code structure.

    By "table" do you mean JTable?

    If so, then there are great tutorials that explain how to create a JTable, and no this doesn't have to be done in another class, but it certainly can be. Regarding your other problems, I'm not sure how to help you as your questions are too general. Are you completely unfamiliar with how to create and use ActionListeners? If so, there are great tutorials for that as well, and I recommend that you start there. If that's not the problem and it's a more specific problem, then by all means show us your code and ask your question, but again, make it as specific as possible.

    And please, if you don't want to antagonize folks, don't bump a question < 12 hours after posting it. Come on now. We're volunteers and shouldn't be rushed.

  4. #4
    stuckonjava is offline Senior Member
    Join Date
    Jan 2012
    Posts
    151
    Rep Power
    3

    Default Re: Help with Table and code structure.

    Thanks for the reply, I have the column array for the JTable sorted however I don't know what to put in the 2d array for data as the data is data retrieved from the internet, so there is no fixed number of rows as this purely depends on what the user searches for. I have have combo boxes in my main gui marking the "to" and "from" dates which the user wants to see information of. Could you give any advice on hwo I can fill my table up with the relevant information? I have the URLReader method already.

    How would I go about creating the table in another class, because for the gui which the user types in their query I created a new object of it's class in the main method. Would I have to do this for the table class as well ?


    I know how action listeners work but I've never used them to open a new window before.

    I apologize for the bump.

    Thanks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with Table and code structure.

    Quote Originally Posted by stuckonjava View Post
    ... I have the column array for the JTable sorted however I don't know what to put in the 2d array for data as the data is data retrieved from the internet, so there is no fixed number of rows as this purely depends on what the user searches for.
    Then consider using a DefaultTable model using the constructor that takes the column name array and the row count. Pass in 0 for your initial row count. Then when you create your JTable make this model the table's model by either passing the model into the JTable's constructor or using the table's setModel(...) method.


    I have have combo boxes in my main gui marking the "to" and "from" dates which the user wants to see information of. Could you give any advice on hwo I can fill my table up with the relevant information? I have the URLReader method already.
    I don't think that the question above is answerable until you tell us the details. You're asking this as if you assume we know what the rest of your code looks like and as if we can read your mind. We don't, and we can't.


    How would I go about creating the table in another class,...

    You create a JTable in "another class" just like you'd create a JTable in "this" class. Sorry, but for me the question doesn't make much sense. Perhaps what you're stumped on is how to pass information into another class so that it can use this information to create a JTable. If so, then pass the information in via method or constructor parameters.


    ...because for the gui which the user types in their query I created a new object of it's class in the main method. Would I have to do this for the table class as well ?
    Possibly. It all depends on the goals of your program, again the details of which are unclear to us.


    I know how action listeners work but I've never used them to open a new window before.
    The code for creating windows is well spelled out in the Swing tutorials, and so all it would take would be to call this code in the ActionListener. But having said that, be careful that you're not spitting too many windows at the user as this can get distracting. Often you'll want your GUI to have one main window and instead to swap "views" in this window via a CardLayout.

Similar Threads

  1. Decision structure truth table
    By JMaste in forum New To Java
    Replies: 2
    Last Post: 07-14-2010, 07:31 AM
  2. UML, robust code, structure questions
    By mac in forum New To Java
    Replies: 2
    Last Post: 12-22-2009, 11:06 PM
  3. Code Customiser on Swing Table
    By quddusaliquddus in forum New To Java
    Replies: 6
    Last Post: 09-24-2009, 06:29 PM
  4. Replies: 1
    Last Post: 10-20-2008, 12:58 PM
  5. data structure code
    By vgvt in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 02:49 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
  •