Difference between revisions of "CSC212 Lab 15 2014"
(→First Contact) |
(→Explore the Code) |
||
Line 28: | Line 28: | ||
::* get the dimension of the grid | ::* get the dimension of the grid | ||
::* get the adjacency list of a vertex | ::* get the adjacency list of a vertex | ||
− | * Change the '''probability100''' variable; it controls the probability of creating an edge between a vertex and its neighbors. The lower the value, the less connected the graph is. The closest to 100, the more fully interconnected the vertices get. Run the | + | * Change the '''probability100''' variable; it controls the probability of creating an edge between a vertex and its neighbors. The lower the value, the less connected the graph is. The closest to 100, the more fully interconnected the vertices get. Run the applet again. |
Revision as of 09:59, 27 November 2014
--D. Thiebaut (talk) 09:43, 27 November 2014 (EST)
This lab introduces the Model-View-Controller (MVC) system for implementing Graphical User Interfaces (GUI). Please review the slides from the MVC lecture notes if necessary.
First Contact
- Create a new project, or add new files to an existing project. You will need to import core.jar from the Processing 2 app into your project, and then add it to the build path.
- You need to create 3 different classes, one for the controller, one for the viewer, and one for the model.
- MVC1_controller.java
- MVC1_viewer.java
- MVC1_model.java
- This tutorial contains the code for all three classes. Copy/paste the code into your three classes.
Run
- The starting class is the viewer. It's the applet class.
- Run it. Play with the applet to understand how it works.
Explore the Code
- Read the code for the model. Notice that it contains the bare definition of a graph, its vertices, and its edges, and not much else. That's what a model should contain.
- Look at the main public methods. They are few. They mostly allow one to
- initialize a graph, if we want one already made.
- add an edge
- get the dimension of the grid
- get the adjacency list of a vertex
- Change the probability100 variable; it controls the probability of creating an edge between a vertex and its neighbors. The lower the value, the less connected the graph is. The closest to 100, the more fully interconnected the vertices get. Run the applet again.