Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 241 – Computer Programming II Lab Kalpa Gunaratna –

Similar presentations


Presentation on theme: "CS 241 – Computer Programming II Lab Kalpa Gunaratna –"— Presentation transcript:

1 CS 241 – Computer Programming II Lab Kalpa Gunaratna – kalpa@knoesis.orgkalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

2 Contact  Contact by e-mail  kalpa@knoesis.org kalpa@knoesis.org  Office hours  376 Joshi  Mondays & Wednesday 3:00 pm – 4:00 pm

3 Container  Each GUI component should be a part of the Containment Hierarchy.  JFrame & JPanel are two types of containers.  Containers are used to hold components.  Normally JPanel is placed inside a JFrame and in this way, JPanels could be arranged in any desired way and place components.  JFrame has a content pane and menu bar.  JPanel is a general purpose container.

4 Simple Graphics  For drawing, Graphics g object reference is used.  Each Container has Graphics g object & that reference could be used to draw any shape inside that specific Container.  Ex: to draw inside a JPanel, the relevant Graphics g object should be used. It could be parsed to a different class and used outside of the JPanel to draw shapes in JPanle for example.  paintComponent method has Graphics reference for drawing in JPanel.

5 In lab  Make "Ball" specific information and details into a separate class called Ball.  draw() and move() methods should be implemented in Ball class (you may keep the declaration of these methods in BallPanel and call Ball's methods inside these methods for better coding practices).  Values for variables in Ball class should be done in the Ball Constructor (random numbers in ranges mentioned in the assignment).  Use Math.random() to generate random number x in the range 0 <= x < 1.

6 Post lab  Make ArraList of Ball objects.  Handle each ball object in the list accordingly. paint() & draw() methods for each ball should be invoked accordingly.  Get the prefered number of balls from user in the BallPanel constructor using a dialog box. You can use a JoptionPane for this.

7 Reminders  Do not put JavaDocs in multiple line comments.  JavaDoc - /** */  Multiple line - /* */  Write test cases for the given format. Ex: input should also be printed.  == is checking whether its the same reference. Use compareTo or equalTo.  Marks will be deducted if net beans projects are not submitedto WebCT.


Download ppt "CS 241 – Computer Programming II Lab Kalpa Gunaratna –"

Similar presentations


Ads by Google