Java Reference
In-Depth Information
youȓ and asks the recipient to click on an attachment masquerading as a love
letter. In fact, the attachment is a script file that is executed when the user clicks
on it. The script creates some damage on the recipient's computer and then,
through the power of the scripting language, uses the Outlook e-mail client to
mail itself to all addresses found in the address book. Try programming that in
Java! By the way, the person suspected of authoring that virus was a student who
had submitted a proposal to write a thesis researching how to write such
programs. Perhaps not surprisingly, the proposal was rejected by the faculty.
477
478
Why do we still need Java if scripting is easy and fun? Scripts often have poor
error checking and are difficult to adapt to new circumstances. Scripting
languages lack many of the structuring and safety mechanisms (such as classes
and type checking by the compiler) that are important for building robust and
scalable programs.
10.9 Using Inheritance to Customize Frames
As you add more user interface components to a frame, the frame can get quite
complex. Your programs will become easier to understand when you use inheritance
for complex frames.
Define a JFrame subclass for a complex frame.
Design a subclass of JFrame . Store the components as instance fields. Initialize
them in the constructor of your subclass. If the initialization code gets complex,
simply add some helper methods.
Here, we carry out this process for the investment viewer program in Chapter 9 .
public class InvestmentFrame extends JFrame
{
public InvestmentFrame()
{
account = new BankAccount(INITIAL_BALANCE);
// Use instance fields for components
label = new JLabel(Ðbalance: Ñ +
account.getBalance());
// Use helper methods
createButton();
Search WWH ::




Custom Search