1 Complete the UML sequence diagram below that explains how

1. Complete the UML sequence diagram below that explains how the following program creates a Timer and JButton instance and processes events from the button and timer instances. Write a short description that briefly explains your digram.

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class A_Panel extends JPanel   {

       private static final long serialVersionUID = 1L;

       private static final String ACTION_GREEN=\"Ready\";

    private static final String ACTION_RED=\"Working\";

    private JButton mButton;

    private Timer mTimer;

    public static void main(String[] args) {

        JFrame frame = new JFrame();    // make frame

        frame.setSize(480, 600);

        frame.getContentPane().add( new A_Panel() ); // add this app to frame

        frame.setVisible(true);

    }

    public A_Panel() {

        setLayout( new FlowLayout());

        mButton = new JButton(\"Ready\");                    // create and add button to panel

        mButton.setBackground(Color.GREEN);

        mButton.setActionCommand(ACTION_GREEN);

        mButton.setPreferredSize(new Dimension(200, 100));

       

        mButton.addActionListener( new ActionListener(){

              @Override

            public void actionPerformed(ActionEvent e){

                     // change button to RED. Start timer.

                if (e.getActionCommand().equals(ACTION_GREEN)) {

                    mButton.setText(ACTION_RED);                  

                    mButton.setBackground(Color.RED);

                    mButton.setActionCommand(ACTION_RED);

                    mTimer.start();                             

                }

            }

        });

       

        add(mButton);

       

        mTimer = new Timer(1000, new ActionListener() {   // create a 1 second timer

              // on timer event, change button color back to green. stop timer.

              @Override

              public void actionPerformed(ActionEvent e){

                mButton.setText(ACTION_GREEN);                 

                mButton.setBackground(Color.GREEN);

                mButton.setActionCommand(ACTION_GREEN);

                mTimer.stop();                 

              }

        });

    }

}

System start app Actor press green button Actor create A Panel JButton create create addListener actionPerformed. Button Listener Timer Timer Action

Solution

Sequence diagrams in UML show how objects interact with each other and the order those interactions occur. It’s important to note that they show the interactions for a particular scenario. The processes are represented vertically and interactions are show as arrows. It is a construct of a message sequence chart.Sequence diagrams are sometimes called event diagrams or event scenarios.

The rectangular boxes represent the functionality of the system. Sequence diagrams gives the inforamation of how the user(ACTOR) is using the using, If a action is performed by the user the change in the state of the system takes place. Thus , sequence diagram helps in finding out the lifetime of the object.Now our system Consists of a Panel that contains a button and when the user press that button a timer action is performed. Lets take a look at the flow of events or simply the lifetime of an object.

Here the Actor represents the user.so they may be one or many actors using the system simultaneously.The vertical lines are called the lifelines of the system.So, when the actor starts the app the system begins.A frame is created (SYSTEM in UML) has the size of 480 *640 with contents as a button is created(Instance of a button is called in the code) with a background color green.Then a actionListener is added to the button.Now its for a user to take an action.Now when the user presses the button then a actionListner is called from a panel to a button.now certain chages takes place. such as changing the text color to red, background color to red and the timer is intiated for 1 sec and sets back to the original position .Thus the action of the button is completed So, now the system (FRame) sends a lifeline to button listener that the action is completed (ACTIONPERFORMED).

1. Complete the UML sequence diagram below that explains how the following program creates a Timer and JButton instance and processes events from the button and
1. Complete the UML sequence diagram below that explains how the following program creates a Timer and JButton instance and processes events from the button and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site