6 marks iii show what the q4frame looks like after

This preview shows page 9 - 13 out of 24 pages.

(6 marks) iii) Show what the Q4Frame looks like after the user has entered “ 2 ” into the TextField , textField1 , “ 6 ” into the TextField , textField2 , and pressed the B Button. (6 marks)
Image of page 9

Subscribe to view the full document.

Question/Answer Sheet - Page 10 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED Question 5 (15 marks) You are required to complete the Q5Frame definition. The Q5Frame contains two Button s and one TextField . When the Frame first appears to the user it looks like this: To begin with, the Q5Frame displays a series of 5 squares each of size 10 pixels. Initially the Q5Frame displays the 5 squares with a horizontal orientation. The TextField displays the number 5. When the user clicks on the “ CHANGE ” button, the series of squares is displayed in the opposite orientation i.e. if they are currently displayed horizontally then after the user clicks on the CHANGE ” button the squares are then displayed vertically, if the squares are currently displayed vertically then after the user clicks on the “ CHANGE ” button they are displayed horizontally. For example, below is the Frame after the user has clicked on the “ CHANGE ” button: If the user now clicks on the “ CHANGE ” button again, the 5 squares will again appear horizontally as they are in the first screenshot above. Whenever the user clicks on the “ NEW ” button, a random number of squares (the number of squares is between 1 and 5 inclusive) are displayed either horizontally or vertically; there is a 50% chance that they are displayed horizontally and a 50% chance that they are displayed vertically. For example, below is the Frame after the user has clicked on the “ NEW ” button:
Image of page 10
Question/Answer Sheet - Page 11 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED In this case the random number generated is 3 and the 3 squares are displayed vertically. The random number is displayed in the TextField . If the user now clicks on the “ CHANGE ” button the squares are displayed in the opposite orientation i.e. horizontally. Below is the Frame after the user clicks on the “ NEW ” button again:
Image of page 11

Subscribe to view the full document.

Question/Answer Sheet - Page 12 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED In this case the random number generated is 4 and the 4 squares are displayed vertically. The random number is displayed in the TextField . Note: In the paint() method of the Frame definition you will find constants which give the x , y position of the topmost square when the squares are displayed in vertical orientation and the x , y position of the leftmost square when the squares are displayed in horizontal orientation. You should use these constants in your code. import java.awt.*; import java.awt.event.*; public class Q5Frame extends Frame { private static final int MAX_NUMBER_BOXES = 5; //the components displayed in the Frame private Button newB, changeB; private TextField numBoxesT; //the number of boxes currently displayed private int numBoxes; //the orientation of the boxes private boolean isHorizontal; public Q5Frame(String title,int x,int y,int width, int height) { setBounds(x,y,width,height); setTitle(title);
Image of page 12
Image of page 13
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Subroutine, ........., Return statement, Randomness, Void type

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern