Java Reference
In-Depth Information
Exercises
Before you start the exercises below, make sure that you to have either the
Finances database or the Sales database (both from Chap. 7 ) set up as an ODBC
data source.
10.1 (i) If you are using the Finances database, then you need take no action here.
If you are using the Sales database, however, you will need to re-code
(and re-compile) JDBCBean.java so that the bean is accessing the Stock
table from the Sales database.
(ii) Create a simple (non-GUI) application that makes use of JDBCBean . Your
program should simply display the query results retrieved by the bean.
Note that, since the bean 'throws' ClassNotFoundException and SQL
Exception , your code will have to catch (or throw) these exceptions.
10.2 Modify the code for JDBCGUI.java from Sect. 7.9 to produce a GUI-driven
application that makes use of JDBCBean and a JTable to display the query
results. In so doing, remember (if you are using the Finances database) that
the bean concatenates surname and fi rst names, effectively reducing the num-
ber of display fi elds from four to three. In addition to the table of results, the
application should provide just a simple 'Quit' button. (Once again, you will
have to cater for the ClassNotFoundException and SQLException not han-
dled by the bean.)
10.3 (i)
Create a JavaBean that encapsulates a very simple calculator that will
allow the user to enter an arithmetic expression involving two operands.
The JavaBean should be implemented as a subclass of JPanel and the
user should be able to carry out the four basic arithmetic operations (using
operators '+', '−', 'x' and '/'). Two buttons should be provided, the fi rst
of these to calculate and display the result of the current calculation and
the second to move the result into the fi eld for the fi rst operand (with
subsequent fi elds being cleared), so that the user can carry out further
operations on this result. The layout should look something like that
shown below .
Note that no main method is required.
(ii) Create a manifest fi le for the above bean and package the bean and its
manifest within a JAR fi le. Then execute the following command from
the command line (substituting your own JAR fi le name, if yours is not
called Calculator.jar ) :
Search WWH ::




Custom Search