I was sick the day on our review for this programming assignment so I am in kind of a dillema with a jerk for a professor...What I am going to do is after each section show you guys what I have and I don't think I should have too many problems but would it be possible for feedback. If not thats ok I was just seeing if that is possible. This is what I have so far from completing section 2 and I think I got it done right just making sure.....
//packages to import
import java.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Checkerboard extends Frame implements ActionListener
{
private Panel topPanel = new Panel();
TextArea topDisplay[] = new TextArea[16];
private Panel bottomPanel = new Panel();
private TextField startField = new TextField(10);
private TextField stopField = new TextField(10);
private TextField stepField = new TextField(10);
private Label startLabel = new Label ("Start");
private Label stopLabel = new Label ("Stop");
private Label stepLabel = new Label ("Step");
private Button goButton;
private Button clearButton;
private int start;
private int stop;
private int step;
public Checkerboard()
{
}//end action listener
}//end class
this is my instructions:
This will incorporate arrays, for loops, and Frames all in one.
Create a panel containing an array of 16 TextArea components that change color to correspond with the start, stop, and step values entered by the user. Perform the following tasks to create the Checkerboard Array application shown below. When the user enters the start, stop, and step fields and then clicks the Go button, the results are also shown below.
1. Call your application Checkerboard.java
2. You will need the following variables… declare them as private:
a. 16 component TextArea array
b. a Panel to hold the array
c. 3 TextField components with length of 10
d. 3 int variables to receive the start, stop, and step values
e. 3 Labels to display the words Start, Stop, and Step
f. a Go button
g. a Clear button
h. a Panel to hold the 3 TextFields, 3 Labels, and the 2 Buttons
3. Create a constructor method to:
a. construct each of the components declared above and initializes the start, stop, and step variables to zero (when constructing the TextArea components, use the following parameters: null, 3, 5, 3)
b. set the Frame layout to BorderLayout
c. write a for loop to loop the array and set each of the 16 TextArea components in that array so they cannot be edited. In the same loop, set each of the TextArea components text to be 1 more than the index number. Also in this same loop, set the background of each of the TextArea components to white.
d. set the Panel for the TextArea components to GridLayout with 4 rows, 4 columns, and both gaps set to 10
e. set the Panel for the TextFields, Labels, and button to GridLayout with 3 rows, 3 columns, and both gaps set to 5
f. add the components to their respective Panels
g. make the buttons clickable
h. place the Panels in the Frame… put one in the NORTH and one in the CENTER
i. Enter the addWindowListener() method described in the chapter… this is the method that overrides the click of the X so it terminates the application
4. In your actionPerformed() method:
a. convert the data in your TextFields to int and store them in the variables declared above
b. write a loop that goes through the array setting every background color to blue
c. write another loop that’s based on the user inputs. Each time the loop is executed, change the background color to yellow (so… start your loop at the user’s specified starting condition. You’ll stop at the user’s specified stopping value. You’ll change the fields to yellow every time you increment your loop based on the step value. REMEMBER: Your displayed values are 1 off from your index numbers!!)
5. Write a main() method that creates an instance of the Checkerboard Frame.
a. set the bounds for the frame to 50, 100, 300, 400
b. set the title bar caption to Checkerboard Array
c. use the setVisible() method to display the application Frame during execution
6. After you get all of this complete, include error handling to make sure:
a. the values entered in the TextFields are valid integers
b. the start value is greater than or equal to 1 and less than or equal to 16
c. the stop value is greater than or equal to 1 and less than or equal to 16
d. the step value is greater than or equal to 1 and less than or equal to 16
e. the start condition is less than the stop condition
f. when an error occurs, give an error message in a dialog box that is specific to their error, remove the text from the invalid field, and put the cursor in that field so the user has a chance to re-enter… this can be accomplished by using multiple try/catch statements
g. only change the colors if the numbers are valid
7. Create a clear button as seen in the example below. This button should:
a. clear out all 3 TextFields
b. change the background color of all TextArea array elements to white
c. put the cursor in the start field