This section demonstrates how to draw and edit a sequence diagram that generates source code. To generate source code from a sequence diagram, you will:
Creating a project and classTo create a project and class, follow these steps: 1. Create a Together Java Modeling Project. In the New Project dialog, enter a project name, and click Finish. The Diagram view opens displaying the default package diagram. 2. Create a new class on the diagram, and name it MyApplication. 3. Right click on the MyApplication class, and select New > Operation from the context menu. The in-place editor activates. 4. Create a main class method by entering the following code in the in-place editor: main(args: String[]):void 5. Press Enter. The new main() method is created.
|
![]() |
Generating a sequence diagram from a classTo generate a sequence diagram from the main method, perform these steps: 1. Right click on the main method, and select Generate Sequence Diagram from the context menu. The Generate Sequence Diagram wizard displays. 2. Click Next, accepting the default settings for the first page of the wizard. 3. Click Finish, accepting the default settings for the second page of the wizard. The sequence diagram, MyApplication.main[1], opens in a new diagram tab of the Diagram view. |
![]() |
|
5. Draw message #1.3. Similar to Step 3, use the Select Operation
dialog (Select Operation > More), expand the Component node, and select
the setSize(int,int):void method. Invoke the in-place editor for the message,
and enter (600,400) after the closing curly brace as shown here: The message label becomes: 1.3: setSize(600,400):void 6. Draw message #1.4. Use the Select Operation dialog, expand
the Component node, and select the setLocation(int,int):void method. Invoke
the in-place editor for the message, and enter (50*i,50*i) after the closing
curly brace as shown here: The message label becomes: 1.4: setLocation(50*i,50*i):void 7. Draw message #1.5, Using the Select Operation dialog, expand the Window node, and select the show() method from the list. The message becomes: 1.5:show():void |
![]() |
|
2. The second page of the wizard displays changes that are necessary to perform refactoring. Notice the sections on the page highlighting the original source code to be replaced and the refactored source code to replace it. Click Finish. |
![]() |
|
The Editor displays the implementation code. Message labels, for which implementation code has been generated, display in bold on the diagram. If code generation fails for certain messages, those messages do not display in bold. 3. On the sequence diagram, double click one of the message links displayed in bold, and observe that the Editor scrolls to the point of appropriate method invocation. 4. In the Editor, add an import statement for javax.swing. Double click on the first occurrence of JFrame in the code. Right click on JFrame, and select Source > Add Import from the context menu. |