Solved

Managing events within an applet

Posted on 1998-09-01
2
157 Views
Last Modified: 2010-03-30
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
Comment
Question by:dirku
2 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 50 total points
Comment Utility
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
 

Author Comment

by:dirku
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now