Unit #11: Programming Assignment#13
Total
Points: 20
Problem #1:
Modify
the solution to Example Program #1 such that, instead of simply randomly
drawing lines, the program randomly draws rectangles, ovals and round
rectangles.
Modify the “paintComponent” method as below:
· Before drawing any of
the shapes, set the color.
· Increase the count by
1.
· Randomly generate a
number between 1 and 4:
a)
If the
number generated is 1, draw the line as in Problem #1
b)
If the
number generated is 2, draw a rectangle
o
g.fillRect (int
x, int y, int length, int width) - derscribes the x
and y coordinates of the top left corner and the length and width of the
rectangle.
c)
If the
number generated is 3, draw an oval
o
g.fillOval (int
x, int y, int length, int width) – describes the x and y coordinates of the top
left corner and the length and width of the rectangle in which the oval is
inscribed.
d)
If the
number generated is 4, draw a rounded rectangle.
o
g.fillRoundRect (int
x, int y, int length, int width, int arc_h, int arc_w)
– describes the x and y coordinates of the top left corner and the length and
width of the rectangle and the length and width of the arc on all four corners
of the rounded rectangle.
Problem #2:
In this program, you will write a GUI (applet) which implements a
login screen. The graphic objects that make up the GUI are as below:
· A
JLabel with the text, “Login”
· A
JTextField for entering the login
· A
JLabel with the text, “Password”
· A
JTextField for entering the password
· A
JButton with the text, “Login”.
Once you enter the login and press the enter key, your program
should inform the user as specified below:
· If
the chosen login name does not contain at least one uppercase letter and
at least one number character (0-9), say, “Login should have at least
one uppercase letter and one number”. Otherwise, the program should say, “Login
was properly chosen”.
· If
the chosen login name has already been taken, use a JOptionPane
object to say, “Login name has already been taken”. Your program should use a
string array to maintain a list of login names that have already been chosen.
· If
the chosen login name has not been taken, use a JOptionPane
object to say, “Login name has been created”.
Once you enter the password and click on the password button, your
program should inform the user as specified below:
· If
the chosen password does not have at least one uppercase letter and at
least one number character (0-9), say, “Password should have at least one
uppercase letter and one number”. The other characters in the password could be
a combination of alphabets, number characters or any other character. If the
password and the login are appropriate, the program should use a JOptionPane object to say, “Login was Successful”.
The program should handle the following error checks:
· If
the user does not enter any input in the text field for login and simply hits
the enter key or if the user enters the password but has not entered any input
for login and then proceeds to click the button, your program should say, “No
login was entered”.
· If
the user enters a valid input in the text field for login but does not enter
any input in the text field for password and then proceeds to click the button
to login, your program should say, “No password was entered”.
· If
the user does not enter any input in the text fields for login and password and
simply clicks the button to login, your program should say, “No Login and
Password were entered”.
· As
mentioned before, if either login and/or password does not have at least one
uppercase letter and at least one number character, your program should say so.
Programming
Details:
Your program will need two ActionListener objects that are
implemented as anonymous inner classes:
· The
first ActionListener object should be implemented on the login text field.
· The
second ActionListener object should be implemented on the button that will be
clicked once the password is entered.