2015년 11월 4일 수요일

[OOP - Take home final exam] Due: Nov. 20, 2015 (Updated on OCt. 30, 2015)

[Note-11-04] You don't have to implement a chatting service. Just OMOK....

[Note] Enhance your 2-player online OMOK game with the JavaFx (for GUI) and Socket


- Input Method : Mouse (or  Keyborads)
  Especially, the just exploit a mouse right-button press method to put a stone on the board 

30% of final exam
(Note: Written final exam (70%) + Take-home exam (30%) = Final exam (100%))

[Grading guidelines]
- Object-oriented programming structure (20%)
- GUI (30%)
- Socket communication (10%)
- Exception and error handling (10%)
- Program source comments  (10%)
- OMOK Game function  (20%)

Click here !!

[Probability] HW4 (Due: Nev. 19, 2015)

HW4

2015년 11월 2일 월요일

[OOP] OMOK Game Template

OMOK Game Template using threads

Download

[OO-Java] Sample Code !! - Thread Kill


public class ThreadKill {

public static void main(String[] args) {

// Create tasks
Runnable MyTaskB = new Task2();

// Create threads
Thread thread0 = new Thread(MyTaskB);
thread0.start();
}
}

//The task for printing a character a specified number of times
class Task1 implements Runnable {
int i = 0;
int j = 0;

public void run() {

Thread t = Thread.currentThread();
String name = t.getName();

try {
while (!Thread.interrupted()) {
i += 1;
j += 1;
System.out.println("[" + name + "] " + "i: " + i + " j: " + j);
Thread.sleep(1000);
}
} catch(InterruptedException ex) {
// The interrupt() method interrupts a thread in the following way:
// If a thread is currently in the Ready or Running state,
//    its interrupted flag is set;
// if a thread is currently blocked,
//      it is awakened and enters the Ready state,
//      and a java.lang.InterruptedException is thrown.
// ex.printStackTrace(); //Verify What happens if we take out this statement

}
}
}

//The task class for printing numbers from 1 to n for a given n
class Task2 implements Runnable {

@Override /** Tell the tread how to run */
public void run() {

Thread thread1 = new Thread(new Task1());
Thread thread2 = new Thread(new Task1());
Thread thread3 = new Thread(new Task1());

thread1.start();
thread2.start();
thread3.start();

try {
Thread.sleep(2000);
}  catch(InterruptedException ex) {
// ex.printStackTrace(); //Verify What happens if we take out this statement
}

thread1.interrupt();
thread2.interrupt();
thread3.interrupt();

//thread1.stop(); // Try this One!!
//thread2.stop();
//thread3.stop();

System.out.print("Num: " + 1 + " ");
}
}



[OO-Java] Sample Code !! - Thread Join


public class ThreadJoin {

public static void main(String[] args) {

// Create tasks
Runnable MyTaskB = new Task2();

// Create threads

Thread thread0 = new Thread(MyTaskB);
thread0.start();
}
}

//The task for printing a character a specified number of times
class Task1 implements Runnable {
int i = 0;
int j = 0;

public void run() {

Thread t = Thread.currentThread();
String name = t.getName();

i += 1;
j += 1;
System.out.println("[" + name + "] " + "i: " + i + " j: " + j);
}
}

//The task class for printing numbers from 1 to n for a given n
class Task2 implements Runnable {

@Override /** Tell the tread how to run */
public void run() {

Thread thread1 = new Thread(new Task1());
Thread thread2 = new Thread(new Task1());
Thread thread3 = new Thread(new Task1());

thread1.start();
thread2.start();
thread3.start();

try {
thread1.join();
// System.out.print("Num: " + 1 + " ");
thread2.join();
// System.out.print("Num: " + 2 + " ");
thread3.join();
// System.out.print("Num: " + 3 + " ");
System.out.print("Num: " + 1 + " ");
} catch (InterruptedException ex) {
ex.printStackTrace();
}

}
}