Java Reference
In-Depth Information
When you compiled the Calculator application, Java created a file in
addition to the Java bytecode file. When a program contains an internal class
with the same name as the host file, Java compiles them separately. If you
examine the Chapter06 folder on your floppy disk, you will see the usual Java
bytecode file named Calculator and another file named Calculator$1. The
Calculator$1 file is the compiled Frame object you created and named
Calculator.
Chapter Summary
In this chapter, you learned about using Java's Abstract Window Toolkit to
create a Calculator application with a menu system. You also learned how to set
flags and create an array of Buttons to place in a keypad Panel.
As you designed the menu system for the application, you learned about the
MenuBar, the Menu commands, and the MenuItem commands. You added each
menu component to its respective container and then added the ActionListener
to each of the MenuItems used to create the commands. You also set the action
of each command that the user clicks.
You learned that registering a WindowListener event and overriding the
windowClosing allows you to customize exactly what will happen when the user
clicks the Close button on a frame-based application. You also learned how to
write code to set a window's other attributes using Java's setBounds(), setTitle(),
and setVisible() methods, among others.
As you learned how to code the ActionPerformed() method, you learned
about special classes and methods used to manipulate the system clipboard. You
used the getDefaultToolkit() method from the Toolkit class to access the operat-
ing system tools, and with the getSystemClipboard() method, you learned how
to copy data to the clipboard. The Transferable interface was used to create a
buffer to store the contents from the clipboard and evaluate it before using it in
a paste operation to paste data from the clipboard.
You learned how to use both if statements and switch statements to deter-
mine which button a user clicked on the Calculator application interface. You
also learned how to code the getActionCommand() method to retrieve the
action event from menu clicks and the getSource() method to retrieve the event
object from the numeric and operator button clicks. Finally, you coded the
buttons to display and perform mathematic calculations correctly.
Testing with the System Clipboard
You can use the calculator program to compute a result and then
select and copy the answer into another Windows program, such
as Notepad, Word, or Excel. Try the reverse action of typing a
number in the second application, selecting and copying it, and
then pasting the number into the calculator program. Perform a
mathematical operation, such as adding 10 to the pasted number,
to verify that a valid number was pasted into the calculator.
Search WWH ::




Custom Search