Solved

Managing events within an applet

Posted on 1998-09-01
2
162 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
ID: 1223123
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
ID: 1223124
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Securing Jmx Console and web console 2 65
Java DateChooser? 3 29
replace a word with other 1 40
servlet filter example 37 43
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

920 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

16 Experts available now in Live!

Get 1:1 Help Now