IST 350/CSC 485

braintreesmileΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 8 μήνες)

264 εμφανίσεις

IST 350/CSC 485


Lab
3

More on
Using the Code Editor


Create a lab3 project for the following exercises.


Part I

Adjusting Formatting Style
s


1.

Formatting Java Source Code

The IDE automatically formats your code as you write it. You can also reformat specifi
c lines of
code or even entire files. The following table lists some common formatting commands.

Keyboard
Shortcut

Description of Command

Ctrl
-
Shift
-
F

Reformat the entire file or whatever text is selected in the Source Editor.

Ctrl
-
T

Shift the current

line or selection one tab to the right.

Ctrl
-
D

Shift the current line or selection one tab to the left.

Ctrl
-
E

Remove the current line.

Ctrl
-
Shift
-
T

Comment out the current line or all selected lines with line comments
("//").

Ctrl
-
Shift
-
D

Remove
comments. This command only works for lines that begin with
line comments ("//").

(
http://www.netbeans.org/kb/55/using
-
netbeans/editing.html#76726
)


2.

Change Code Format Styles

-

Open Tools | Options

-

Select Editor to change formatting styles when using the Source editor

-

Change the default Code Folding and Code Completion options to fit your flavor

-

Select the Indentation tab, to change the options and see changes in Preview

-

Select

the Code Templates tab to see default shortcuts for code completion

-

Select the Fonts and Colors panel and change fonts or colors as you wish


3.

Comparing differences between two files

-

select two file nodes in the Projects window

-

choose Tools | Diff


Part I
I

Practicing with a Simple Project


4.

Create a Java Interface

-

Create a new package in the lab3 project and name it
game
.

-

Add a new Java interface named
MoveableShape

into your
game

package.

-

Type in the code as given in the attachment, including Javadoc style

comments

-

Select the underlined
Graphics2D

identifier and select Fix Imports from the
context
-
based short menu to let NetBeans add the
import

statement
automatically.


5.

Create a Java Class That Implements an Interface

-

Add a new Java interface named
Moveabl
eShape

into your
game

package.

-

Add an
implements Icon

clause in the class declaration

-

After the lightbulb icon occurs, click Alt
-
Enter to

o

Fix imports, and again to

o

Implement all abstract methods

-

Complete the constructor/method stubs using code listings pro
vided

-

Fix missing imports and/or other errors as indicated by the Editor

-

You may need to start with the private elements listed at the end of the class first
to avoid errors indicated by NetBeans


6.

Create a Main Class with a
n

Anonymous Inner Class

-

Add a new

Java class into the game package, using the name
CarShape
, and
copy the content from the

corresponding

source file in Lab 3 folder.

-

Add a new Main class
AnimationTester

into your
game

package.

-

Type in the code, use code completion features we’ve learned t
o help as far as
possible

-

Compile and execute the main class. Debug as needed. Observe how the car
image moves. Change the ways the car moves by adjusting values in the constants
as desired.


7.

Converting the Anonymous Inner Class to a Named One

-

Right
-
click
on the
ActionListener

identifier and select
Refactor | Convert
Anonymous Class

to Inner in the short menu, add a class name such as
TimerListener

when prompted

-

Change the extends keyword to implements as necessary

-

Move the content in the main method to the

dummy constructor created by
NetBeans, and add the following line in the main to kick off the application

AnimationTester

t = new
AnimationTester
();

-

Recompile and execute the main class, until everything works.