Constants startleft and top once the timer has

This preview shows page 22 - 27 out of 30 pages.

constants, START_LEFT and TOP ). Once the Timer has started, the number of squares displayed across the JPanel increases (one more square is displayed each tick of the Timer) until 30 squares are displayed across the JPanel. Once the number of squares has reached 30, the number of squares reduces by one at each tick of the Timer object until the number of squares displayed is one, then the number of squares increases again, and so on. Whenever the user presses the RIGHT arrow key the Timer should start and the number of squares should continue increasing/decreasing across the JPanel. Whenever the user presses the LEFT arrow key the Timer should stop until the RIGHT arrow key is pressed again. Below are some screenshots of the JPanel in action. Screenshot 1 shows the JPanel when it is first displayed. Screenshots 2, 3 and 4 show the JPanel as the number of squares increases across the JPanel. Screenshots 5 and 6 show the JPanel as the number of squares start decreasing. NOTES: In your code you MUST use the instance variables and constants which have been defined. 1. 2. 3. 4. 5. 6. .…
Image of page 22

Subscribe to view the full document.

Question/Answer Sheet - Page 23 - CompSci 101 ID: ........................................................ CONTINUED import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AJPanel extends JPanel { private static final int START_LEFT = 40; private static final int TOP = 30; private static final int SIZE = 20; private int numberOfRects; private boolean isIncreasing; private Timer t; public AJPanel() { numberOfRects = 1; isIncreasing = true; } public void actionPerformed(ActionEvent e) { final int MAX = 30; final int MIN = 1;
Image of page 23
Question/Answer Sheet - Page 24 - CompSci 101 ID: ........................................................ CONTINUED } public void paintComponent(Graphics g) { super.paintComponent(g); int x = START_LEFT; } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {} } (7 marks)
Image of page 24

Subscribe to view the full document.

Question/Answer Sheet - Page 25 - CompSci 101 ID: ........................................................ CONTINUED Question 9 (7 marks) The Time24Hr class has now been altered to include hours, minutes and seconds. Complete the addSeconds() method below so that any number of seconds can be added to the clock (e.g., 120 seconds, 725 seconds, etc.) and the correct numbers of hours, minutes and seconds will be added to the clock. public class Time24Hr { private int hour; private int minutes; private int seconds; public Time24Hr(int h, int m, int s) { hour = h; minutes = m; seconds = s; } public void addSeconds(int extraSeconds) { } } (7 marks)
Image of page 25
Question/Answer Sheet - Page 26 - CompSci 101 ID: ........................................................ CONTINUED Question 10 (8 marks) Define a class for Students . Your class should have the following instance variables of the following types: String name String email Course[] courses Your class should include a constructor method, accessor and mutator methods for the three instance variables and a toString() method that returns a String containing the Student object’s information. The format of the toString() method is not important as long as the toString() method returns a String with all the information about the Student object.
Image of page 26

Subscribe to view the full document.

Image of page 27
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Method, Subroutine, ... ..., JPanel, Mutator method

{[ 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