COSC4301 Program-7                                     Due:     11/27/2012

                                                 Basic Swing GUI Design

 

Objectives:

1. Design a JFrame class to contain the two JPanels, textPanel and buttonPanel.

2. Create two JTextAreas, numberArea and wordArea.

3. Create four JButtons, numberButton, textButton, clearButton and exitButton.

4. Register this JFrame object as a listener to receive events from above four buttons.

5. Define actionPerformed (ActionEvent e) to handle action events.

 

Define a class MyFrame that extends JFrame and implements ActionListener by defining its constructor

that does the following:

1. Sets its size to 400-by-300.

2. Creates two panels called textPanel and buttonPanel to be added to the JFrame being created using BorderLayout manager.

3. Creates two JTextAreas called numberArea and wordArea to contain up to 30 lines of 40 characters per line.

4. Add these two JTextAreas to the textPanel using FlowLayout manager.

5. Creates four buttons called numberButton, textButton, clearButton and exitButton and add these buttons to the buttonPanel using FlowLayout manager.

6. Register itself as a listener to receive events from these four buttons.

7. Define actionPerformed (ActionEvent e) such that (a) when numberButton is pressed, 150 random integers (between 0 and 9999) are to be obtained and to be displayed in the JTextArea numberArea with 6 numbers per line right-justified. (Note that generated random numbers are of type int and those to be displayed in a textArea are to be of String. So, you need to use a type conversion method such as Integer.toString() which is one of static methods of class Integer), (b) when textButton is pressed, 25 words are to be read from a given input file and displayed in the JTextArea wordArea one word per line. (c) when clearButton is pressed, both text areas are to be cleared (i.e.,blanked) and (d) finally when exitButton is pressed, the program will terminate after printing a farewell message in the text area wordArea.