[Java] Finished assignment 1-b








Java design pattern

View, Model, and Controller



Based on the assignment 1-a which is mostly about Controller,
1-b is about creating View with JavaFX.


The key points for this assignment 1-b, are below.

- Using Update() to update

To use that, 
Class1 (to be updated) extends Observable
Class2 (has update() to update) implements Obersver

Class1 needs to use at least two methods.
setChanged()
notifyObservers();

setChanged() --- is boolean and returns true;
notifyObservers(); 
(notifyObject(Object);)


notifyObjects() --- holds Object and toss to update()


-Using ArrayList or Array
(for passing through notifyObserver() to update())



Arrays.asList<Numbers>(ob1, ob2);
(or Integer, Double>

or 

List<Interger> listObject = new ArrayList<Integer>()
listObject.add(ob1);
ListObject.add(ob2);


or

Int [] arrayObject = {ob1, ob2};



- What is Queue for?
Queue is holding data. In terms of the speed of compiling by JVM, when you execute the code, it happens instantly less than one second, even sometimes, the application crashes. For the console to check the output, there's no problem, but if you want to see how it goes by animationTimer in JavaFX, you will need Queue.

So far, there are two ways to capture the moment, one is using Queue, the other one is using thread.sleep(). Either way is fine if it fits your goal. 

Queue holds data in List.
So, for the this assignment, using asList is easiest way to get data by update().


private Queue<List<Interger>> queueObject = new LinkedList<>();


- Rest parts
for loop in moveTo()


- Surmarry

It seems much easier than the web browser that I had done before. But I spent time as much as I put in the web browser project to figure out which way is the most efficient. Looking forward to assignment 2 based on what I've done.





Comments

Popular Posts