Java Reference
In-Depth Information
public class ExitButton extends TNTButton implements
ActionListener{
public ExitButton () {
// this.setBounds(350, 370, 40, 20);
this .setLabel("Exit");
addActionListener( this );
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
Notice that the step 6 changes are reflected in the source code (i.e., the extends clause was changed and the
setBounds statement was commented out).
Did you see that there is a warning indicated for the import java.awt.Button statement? Because we made
ExitButton a subclass of TNTButton, there is no need to import the Button class. Although this isn't an error, it is
slightly inefficient so RAD flags the statement. This warning is also in the EmpFrame class (from when we made it
a subclass of UsefulFrame instead of Frame). You may have noticed that RAD displays many warnings (such as the
no serialVersionUID field which, by the way, is used for version control). These are actually generated by the Java
compiler, so don't shoot RAD, it's just the messenger. You can either ignore the warnings, give in to the compiler's
nagging and add the field, or change your preferences to ignore the “problem.”
14.
Delete the import statements and generate a default serialVersionUID field (using RAD's
first suggested fix) in both classes.
In the Package Explorer, the warnings icons are removed from the two classes. However, many of the other classes
still are flagged with warnings.
Click Window and then Preferences .
15.
16.
In the Preferences windows, expand Java then Compiler (in the options tree) and select
Errors/Warnings.
17.
On the right of the Preferences window, close Code style and expand Potential
programming problems.
Notice that the first potential problem is Serializable class without serialVersionUID and that the selected RAD
option is to generate a warning.
18.
Click on the option menu button, select Ignore (see Figure 5-10 ), and then click the OK
button.
 
Search WWH ::




Custom Search