Lab 3: BugBattle version 0.1

EEE320 winter 2017

Aims and Objectives

The objective of this laboratory is to practice the understanding of class diagrams and sequence diagrams in UML, and their translations in Java. To complete this goal, you will implement an initial version of the BugBattle software according to the design documented in the Design Specification for BugBattle v0.1.

Submission

You must submit your laboratory report and source code by e-mail to This email address is being protected from spambots. You need JavaScript enabled to view it. before 14h30 on February 15th, 2017. Please submit:

  • A .zip file containing your source code with comments, exported according to instructions in the Eclipse survival guide; and
  • A concise laboratory report, in the laboratory format, as a PDF file, which contains:
    • An introduction;
    • Your answeres to the questions below; and
    • A brief discussion about what you learned, the discoveries you made, which was difficult in the laboratory. Be concise!

Required Tasks

Implementation of BugBattle v0.1

Carefully read the BugBattle v0.1 Design Specification. Implement BugBattle v0.1 as per the UML class diagrams, UML sequence diagrams and method descriptions provided in the specification.

Questions

Answer the following questions in your lab report:

1. The structural model set out in the class diagram of shows that the class SimulationTurn is a nested (or “inner”) class of the class BugBattle. Explain what, exactly, an inner class is and why it is used in this case

2. When you create the BugBattle class and add the “Start” button and associated ActionListener as described in the specification, WindowBuilder will generate a block of code that looks something like this:

btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
    } });
    btnStart.setBounds(230, 6, 75, 29);
    frmBugBattle.getContentPane().add(btnStart);

In the second line you see new ActionListener()... but we know that ActionListener is an interface, not a class, and it is not possible to instantiate an interface. Exactly what is going on here? Hint: see the page General Information about Writing Event Listeners in the Java Tutorial, especially the Inner Classes and Anonymous Inner Classes section.

3. Creating the BugBattle class, as described in the specification, leads to WindowBuilder generating the following main method:

public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                 try {
                    BugBattle window = new BugBattle();
                    window.frmBugBattle.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } 
    });

Explain exactly what the method EventQueue.invokeLater() does. Ensure your explanation includes the roles of the AWT EventQueue and the Runnable interface in the invokeLater method. Hint: have a look at Concurrency in Swing (and the following pages) in the Java Tutorial and the documentation for java.awt.EventQueue and java.lang.Runnable in the Java 8 API Specification.