• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Managing events within an applet

What is the best way to handle events and so on within an applet?
I want to program an applet which holds some components like a JTable, a JComboBox, JPanels, JMenues and so on.
Besides database access should be implemented.
So, what would be the best place to implement the database access?
Presently I implemented an abstract class DBAccess and two subclasses DBAccessDQL for quering the database and DBAccessDML to manipulate data within the database.
But would it be good to implement the database access withing the table's model since this is the class which needs the data from the database?
Of course, the JComboBox needs data from the database, too. So, should I implement database access ability to an extended class of JComboBox too?

The table should handle everything like adding a portfolio tho the table or adding stocks to some portfolios and so on. This must be done within the applet of course, but in the database too! When a portfolio will be added the JComboBox must be aware of this.
How can I handle sth. like this and whta would be the best way?

I thought of sth. like this:
I have a JTable and a DefaultTableModel. To manipulate data I want to program a dialog specific to the table. These three classes could be packaged together to a JavaBean...but I don't know if this would be clever!?
But, of course, other components must be notified about changes within the table.

I don't want to let the main class (applet) a lot of work. I think it would be better to let the component's do the work.
0
dirku
Asked:
dirku
1 Solution
 
diakovCommented:
For the database, I think might want to use the following architecture:
- DBConnectionManager which is responsible for opening, tuning, commiting, closing, the connection to the databases. Also when a database exception occurs it is not necessary your application to stop working, so the ConnectionManager class should do the cleanup and reopen the connections if necessary.
Then you can implement different class definitions for managing the information model of your database. You might need
- DBCreateModel(optional) which is responsible for creating the appropriate tables;
- DBQuery - your suggestion
- DBManipulate - your suggestion

As for the GUI elements you can define DBContentManager which has both knowledge about the database information model and the visual components and it can be responsible for filling the appropriate values and notifying for changes. For example, you can have a static method:
fillComponent(Component c) and in it there is a sequence of if's where you determine which component was the caller and then call the fillComboBox1() method. You can also directly call the methods :-) So you will have all the content filling methods grouped in a class, all the GUI components are clean from knowledge about the database, and the database classes themselves are not full of references to GUI elements.

If you have comments, please post them.

Cheers,
  Nikolay
0
 
dirkuAuthor Commented:
Hadn't enough time to do what you suggested. I will grade you hoping I can contact you again when I have some more questions.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now