Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSSE 221: Software Development Fundamentals - Assignment Solutions, Assignments of Computer Science

Solutions to programming assignments and written homework for the csse 221: fundamentals of software development course. It includes explanations of different layoutmanagers in swing, advantages of extending jpanel, using actionlistener interface, and methods from various interfaces. Also, it provides a code example for a custom mybutton class.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-b0i
koofers-user-b0i 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSSE 221: Fundamentals of Software Development
Honors
Programming assignment (due by Monday 11:59 pm)
Finish Fifteen, as stated in the specification, being sure you have checked in your final,
fully-documented copy to the repository.
Written homework to do before week 4 (due before beginning of class on
Monday, Sept 24).
Answers are to be written in your own words! As usual, please bring hardcopy for
written answers to class to hand in on Monday.
1. Weekly reading. You may also want to refer to the Sun Java tutorial on Swing as
a reference.
2. (15 pts) Describe any three different LayoutManagers in Swing.
SOLUTION:
FlowLayout – adds components from left to right, top to bottom – default layout
manager for JPanel
BorderLayout – adds components in the regions North, South, East, West, and
Center. The region to add the component to must be specified when adding a
component
GridLayout – creates a grid with the specified number of rows and columns.
Unless a location is specified, the GridLayout will fill itself left to right, top to
bottom as components are loaded.
3. (10 pts) Describe any advantages of having a panel be a subclass of JPanel rather
than using JPanel as-is.
SOLUTION:
Extending JPanel allows the developer to reuse all protected and public members
of the JPanel class, rather than rewriting the code. Also, it allows the user to
customize the JPanel by adding new fields/methods, etc.
pf3
pf4

Partial preview of the text

Download CSSE 221: Software Development Fundamentals - Assignment Solutions and more Assignments Computer Science in PDF only on Docsity!

CSSE 221: Fundamentals of Software Development

Honors

Programming assignment (due by Monday 11:59 pm)

Finish Fifteen, as stated in the specification, being sure you have checked in your final, fully-documented copy to the repository.

Written homework to do before week 4 (due before beginning of class on

Monday, Sept 24).

Answers are to be written in your own words!written answers to class to hand in on Monday. As usual, please bring hardcopy for

  1. Weekly reading. You may also want to refer to the Sun Java tutorial on Swing as a reference.
  2. (15 pts) Describe any three different LayoutManagers in Swing. SOLUTION: FlowLayout – adds components from left to right, top to bottom – default layout manager for JPanel BorderLayout – adds components in the regions North, South, East, West, and Center. The region to add the component to must be specified when adding a component GridLayout – creates a grid with the specified number of rows and columns. Unless a location is specified, the GridLayout will fill itself left to right, top to bottom as components are loaded.
  3. (10 pts) Describe any advantages of having a panel be a subclass of JPanel ratherthan using JPanel as-is. SOLUTION: Extending JPanel allows the developer to reuse all protected and public members of the JPanel class, rather than rewriting the code. Also, it allows the user to customize the JPanel by adding new fields/methods, etc.
  1. (6 pts) When is it appropriate to use the ActionListener interface? What method must you implement when using it? SOLUTION: It is appropriate to use the ActionListener interface when you want to catch an action performed by the user. You must implement the actionPerformed(ActionEvent e) method.
  2. (4 pts) Look at the API for MouseListener, MouseMotionListener, KeyListener,and ChangeListener. Name one method from each interface.

SOLUTION: One from each of the following lists MouseListener – mouseClicked(MouseEvent e), mouseEntered(MouseEvent e), mouseExited(MouseEvent e), mousePressed(MouseEvent e), mouseReleased(MouseEvent e) MouseMotionListener – mouseMoved(MouseEvent e) or MouseDragged(MouseEvent e) KeyListener – keyPressed(KeyEvent e), keyReleased(KeyEvent e), keyTyped(KeyEvent e) ChangeListener – stateChanged(ChangeEvent e)

  1. (15 pts) Write a class called MyButton extending JButton. When a button of this type is pressed, it turns another panel, myPanel (stored as a field), the color green. SOLUTION: public class MyButton extends JButton implements ActionListener{ private JPanel myPanel; public MyButton(String message, JPanel myPanel) { super(message); this.myPanel = myPanel;

SOLUTION:

JTextField is used for a single line of input, JTextArea is used for multiple lines of input.

  1. (15 pts) Say you wanted to create a two-dimensional dynamically sized 2D array (i.e. a 2D ArrayList). Write a short paragraph speculating how you might tackle this problem. SOLUTION: Use an ArrayList that contains ArrayLists. This way, the number of ArrayLists can be manipulated by adding to the first ArrayList and the number of objects can be manipulated by adding to the second ArrayList.

Reminder that assistants are in Moench F217 every weekday afternoon and from 7-9pm on Sunday through Thursday nights to help you.