代写java | project | 代做lab – java

java

代写java | project | 代做lab – 这是一个关于java的题目, 主要考察了关于java的内容,是一个比较经典的题目, 涵盖了java等方面, 该题目是值得借鉴的lab代写的题目

project代写 代写project

Problem Set 04

  • C / Summer 2022

———————————–^

The overall strategy for Problem Set 04:^

  1. Your Model class can be based on the SimpleSubject class, and

it implements the Subject interface.^

  1. Your Controller class can be based on the SimpleObserver

class, and it implements the Observer interface.^

  1. In the Main method of your project – here shown in the

Example. java main method,^ create an instance of your Controller class, and make it an

Observer to your Model object.^

  1. When the Controller receives an update() call, it needs to

notify the View object instance.^ Therefore, modify the update() method in the Controller to

receive the 2D array data instance^ from the Model.^

  1. The View object instance can then read all the content of the

Model data^ (as provided to the View by the Controller)^ and redisplay the content of the entire data structure, in

its paintComponent() method.^

And a few hints about organizing your Java program code^ into Model-View-Controller classes,^ for Problem Set 04 and lab Task 10:^

(^)

/// ————————————————————

—————^

// a Main class similar to the provided Example class:^ //^

// the main() method needs to be implemented here,^ // as starting point for the entire Java program^ //^ // instantiate Model, View and Controller^ //^ // make the Controller an Observer for the Model,^ // so that the Controller may receive update() calls.^ //^ // pass the View to the Controller,^ // so that the Controller may call^ // the View’s getDataAndVisualizeIt() method^

/// ————————————————————

—————^

/// Controller class:^

public class PS04Controller implements Observer {^

// provide constructor, etc…^

// every time update() is called, ask the View to redisplay

Model’s data:^

public void update( … pointer to data from Model … ) {^

// data is obtained from the Model, i.e. the array to be
displayed

// ask the View to draw all the data, i.e.^

// call the View object’s getDataAndVisualizeIt(^ … pass the pointer to the data obtained from the

Model … )^

}^

} // end of class PS04Controller^

/// ————————————————————

—————^

/// Model class:^

public class PS04Model implements Subject {^

// inside the Model class, e.g.:^

// constructor, etc.^

public void sortColumns() {^

// do the work for sorting columns…^

// when sorting columns is complete, call

notifyObservers()^

}^

// ...and here you implement all the Model methods that are
needed to sort...

} // end of class PS04Model^

/// ————————————————————

—————^

/// View class:^

// explicit import of every Java class we use from the AWT

package:^ import java.awt.Color;^ import java.awt.Graphics;^ // etc.^

// explicit import of every Java class we use from the Swing

package:^ import javax.swing.JComponent;^ import javax.swing.JFrame;^

public class PS04View extends JComponent {^

// define one JFrame instance variable here, e.g. aJFrame^

// constructor^ public PS04View(int width, int height) {^

// instantiate JFrame^ // configure JFrame^

// inside the PS04View class,^ // refer to itself, i.e. the current instance of

PS04View^ // as ‘this’^

// e.g. to refer to a JFrame variable named aJFrame,^ this.aJFrame = new JFrame();^ …^ …^

}^

// the paintComponent() method is called automatically by

the JComponent itself,^ // every time the JComponent’s repaint() is called:^ public void paintComponent(Graphics pGraphics) {^

// here you have access to a reference to the Model's

data as received by the Controller,^ // and you need to redisplay the entire 2D array of

integer values,^ // as required by^

}^

} // end of class PS04View^

/// ————————————————————

—————^

/// View class, additional/optional approach :^

// if you want to separate each drawing of a point on the

graphics context,^ // in a separate method,^ // you will have to obtain the current graphics context, e.g.

thus:^

(^)

public void drawPoint(int x, int y, int value) {^

// since we are *not* in the JComponent's

paintComponent() method,^ // we need to manually obtain the current graphics

context,^ // (which would otherwise be passed as parameter to

paintComponent()^

// here we obtain the current graphics context from

JComponent,^ // and store it in a local variable:^ Graphics lGraphicContext = getGraphics();^

// in drawPoint(), we have to eventually call

drawOval() :^

// now set the drawing / foreground color^ // … setColor…^ // and draw using the graphics context:^ lGraphicContext.drawOval(….^

// good practice... dismiss the graphics context when

done using it:^ lGraphicContext.dispose()^

}^

// similarly if you want to have a separate clear() method,^ // to clear the background of the graphics context:^

public void clear() {^ // etc…^ }