Solved

Managing events within an applet

Posted on 1998-09-01
2
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

634 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