Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How add functionality from another program  RSS feed

 
Henry Dk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great place
For the past month I have been learning Java reading and studying others work. I program in C and Fortran so coding is not foreign to me OOP is But it is obvious to me that the journey is still ahead of me to fully understand the language.

I have a handle on classes, methods and extend concepts but not sufficiently to feel comfortable in "splicing" code together. The application I am working on in Netbeans uses a GUI with 4 Jtabs. Each tab requires various types of operations to be done on user input. 1st text input and inspection. Done it and works well. 2nd tab will be a pane where the user will select parameters (ComboBox) and set their values (Jtable), this will be a dynamic table as I do not know ahead of time how many parameters the user will want to use in his work. After GOOGLing for a day I found what I want and ran it. Fits like a glove but I do not know how to integrate it into my program as it is being called (obviously) to do everything through its own main method. How should I proceed to add it into my application and to deal with its class extension etc. as this is where I get lost?

Here is the code I want to use,


I think that what I also need to learn and I hope someone can help me on this, is how to organize the code. In C and FORTRAN this was more obvious to me than it is in Java at this stage. My confusion I think is how much should be in the class holding the main method and how much in "other" classes called by the class with main. Where I think I am going at the moment as a beginner is to jam everything into one class. If need be I can put in my own code but for the sake of keeping this one short I will hold back. It is about as long as the one above.

Thank You for any help provided
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to go back to the stage before you write any code. You need to decide what your application is doing and design classes for that. You will get nowhere fast if you try to squeeze more classes into an existing app, unless it is specifically designed to accept them.
The simple way is to write a description of the problem
A greengrocer sells fruit and vegetables. Customers come into the shop and fill baskets with fruit and vegetables. The kinds of fruit include apple oranges bananas and grapes, and the vegetables include potatoes lettuce Brussels sprouts and cabbage. Each fruit has a price per pound. When the fruit has been weighed and the price worked out, the money is put into the till.
Now you consider a class for each of the nouns:
  • greengrocer
  • fruit
  • vegetable[s]
  • Customer[s]
  • shop
  • basket[s]
  • kind[s]
  • apple
  • orange[s]
  • banana[s]
  • grape[s]
  • potato[es]
  • lettuce
  • Brussels sprouts
  • cabbage
  • price
  • pound
  • money
  • till
  • You consider making a class for each of those nouns, but maybe "kind" doesn't need a class of its own. Now the verbs
    sells come fill include has weighed worked out put
    will give some idea of the relationship between the classes.
    You may need other classes, eg Product, allowing you to add other things, eg eggs, which many greengrocers sell, and which I hope you won't go on about, particularly with words like "suck" "grandmother" and "teach".

    You don't want to create a GUI and try to squeeze an app into it, but create an app and then a GUI to accommodate it.

    And welcome to the Ranch
     
    Henry Dk
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Richie for the quick reply.

    I understand what you are saying but I have this gut feeling that I need to see this done in an example. I am a visual learner.

    Here I found one example for how to hand the code to create the multiple tabs without Netbeans,

    http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/node61.html
    but the addition of the special functionality of the example code I showed has me for a loop. I suspect that I need to incorporate what is happening in it
    public class testTable extends JPanel implements ActionListener

    into the method for createPage2() of the above mentioned example.

    This example attempts to do something similar to what I want to do. Distribute distinct steps and functionality into separate tabs to come up with a final result.

    http://webcache.googleusercontent.com/search?q=cache:QX4eq3qi-HYJ:www.functionx.com/java/applications/algebra.htm+java+program+application+start+to+finish+jtab&cd=27&hl=en&ct=clnk&client=firefox-a&source=www.google.com
    (yesterday this link was visible but today you can only see it through Wayback)

    http://replay.waybackmachine.org/20100102070322/http://functionx.com/vb/applications/algebra.htm


    Can you suggest any relatively simple examples to study this process?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!