Exercises
1. Copy
Example4.java into your workspace, compile and execute it.
2. Change
the words Go Heat! to Go Marlins! in
Example4.java. Make sure that the lines line up properly in the String object
when it is displayed by the JOptionPane.showMessageDialog(..) method.
3. Modify
Example4.java again so that the outline of the words Go Marlins! is a triangle instead of a rectangle.
4. Modify Example7.java
to draw a triangle instead of a rectangle containing the words Go Marlins!
5. Modify
the class GUIPattern1.java
to do the following:
·
Add a button so that when the user clicks the button a
JOptionPane pops up asking for a length.
·
After the length is entered draw a filled square
(rectangle with width and length equal to the length that was entered) in the
middle of the panel.
·
Set the location of the frame to 0,0.
6. Implement the BankAccount class given
in class and in the text. Recall the information is a double balance; there is
one constructor that has a double initialBalance as
input (parameter); and the methods are: void deposit(double
amount) , void withdrawal(double amount) and double getBalance().
Test your implementation with the class TestBankAccount.java.
7. Make the corrections on your version
of Assignment Two.
8. Modify SquareExercise.java to draw many Rectangles at
different positions in the draw area instead of just one. Hint: Use a for loop.
9. Look at and start Assignment
Three.
10. Modify ATM2.java
as follows:
·
Write a method void drawBalance(Graphics2D g, BankAccount
account) that draws the balance using g as in the ButtonAction
classes and call the method in each of the classes.
·
Add a JLabel to the drawPanel. Declare the JLabel
“globally” and construct it with the null string.
·
A JLabel object has methods void setText(String s), void setFont(Font f)
and setForeground(Color c). Use these methods to ‘draw”
the balance on the JLabel instead of using the Graphics2D object.
11. Start Assignment
Four.