my work on discrete

discreet

/*
Name: Siti Asmah Binti Ab Aziz

*/

import java.awt.*;
import java.applet.*;

public class shorty extends Applet
{
//initializes the layout
public void init() {
setBackground(Color.white);
for (int i = 0; i<12; i++)
balls[i]=0;
for (int i=0; i<14; i++)
lines[i]=0;
count = 0;
first =0;
second = 0;
step = 0;

}

//handles events
public boolean handleEvent(Event evt) {
if (evt.id == Event.WINDOW_DESTROY) System.exit(0);
return super.handleEvent(evt);
}

//for mouse clicks
public boolean mouseDown(Event evt, int x, int y) {
if (count == 0) {
if(50 < x && x < 70 && 40 < y && y < 60) {
if(count == 0)
first = 1;
else if (count == 1)
second = 1;
count++;
repaint();
return true;
}
else if( 300 < x && x < 320 && 50 < y && y < 70) {
if(count == 0)
first = 2;
else if (count == 1)
second = 2;
count++;
repaint();
return true;
}
else if(200 < x && x < 220 && 30 < y && y < 50) {
if(count == 0)
first = 3;
else if (count == 1)
second = 3;
count++;
repaint();
return true;
}
else if(100 < x && x < 120 && 150 < y && y < 170) {
if(count == 0)
first = 4;
else if (count == 1)
second = 4;
count++;
repaint();
return true;
}
else if(175 < x && x < 195 && 100 < y && y < 120) {
if(count == 0)
first = 5;
else if (count == 1)
second = 5;
count++;
repaint();
return true;
}
else if(30 < x && x < 50 && 100 < y && y < 120) {
if(count == 0)
first = 6;
else if (count == 1)
second = 6;
count++;
repaint();
return true;
}
else if(175 < x && x < 195 && 125 < y && y < 145) {
if(count == 0)
first = 7;
else if (count == 1)
second = 7;
count++;
repaint();
return true;
}
else if(125 < x && x < 145 && 75 < y && y < 95) {
if(count == 0)
first = 8;
else if (count == 1)
second = 8;
count++;
repaint();
return true;
}
else if(90 < x && x < 110 &&80< y && y < 100) {
if(count == 0)
first = 9;
else if (count == 1)
second = 9;
count++;
repaint();
return true;
}

}

if (count == 3) {
if(700 < x && x < 800 && 0 < y && y < 15 ||
300 < x && x < 400 && 60 < y && y < 75 ) {
init();
repaint();
return true;
}
}
else {
if(700 < x && x < 800 && 0 < y && y < 15) {
init();
repaint();
return true;
}
else if(400 < x && x < 800 && 60 < y && y < 75) {
step=1;
count=3;
repaint();
return true;
}
}

return true;
}

public void paint( Graphics g )
{
g.setColor(Color.black);
g.fillRect(700, 0, 100, 175); // draw text box on the right
g.setFont(new Font(“Times Roman”, Font.BOLD, 13));
g.setColor(Color.yellow); // draw text on the right
g.drawString(“Reset”, 722, 15);

g.setColor(Color.white);
if(count == 0) {
g.drawString(“Click on a”, 705, 30);
g.drawString(“point and”, 705, 45);
g.drawString(“I will find”, 705, 60);
g.drawString(“the path”, 705, 75);
g.drawString(“closest to”, 705, 90);
g.drawString(“the blue point”, 705, 105);
}
else if (count == 3) {
g.drawString(“click”, 722, 60);
g.drawString(“to reset”, 715, 90);
g.drawString(“the area”, 715, 105);
g.setColor(Color.yellow);
g.drawString(“here”, 725, 75);
}
else {
g.drawString(“click”, 722, 60);
g.drawString(“to see the”, 711, 90);
g.drawString(“shortest path”, 706, 105);
g.setColor(Color.yellow);
g.drawString(“here”, 725, 75);
}
//draw line (from,from,to,to)
g.setColor(Color.lightGray);
g.drawLine(60, 50, 210, 40); //line 1&3 0

g.drawLine(40, 100,110, 80); //line 6&9 1
g.drawLine(40, 100, 110, 160); //line 6&4 2
g.drawLine(210, 40, 310, 60); //line 3&2 3
g.drawLine(310, 60, 185, 110); //line 2&5 4
g.drawLine(185, 110, 135, 85); //line 5&8 5
g.drawLine(185, 110, 185, 135); //line puduraya&7 6
g.drawLine(185, 135, 110, 160); //line merdeka stadium&istana 7
g.drawLine(135, 85, 210, 40); //line centralmarket&Masjid jamek 8

g.drawLine(110, 80, 135, 85); //line centralmarket & NatinalHm

// name the node
g.setColor(Color.black);
g.drawString(“National Monument”, 70, 50);//1
g.drawString(“Natinal Art gelery”, 320, 60);//2
g.drawString(“Masjid jamek”, 220, 40);//3
g.drawString(“Istana Negara”, 120, 160);//4 //100, 150
g.drawString(“Puduraya”, 195, 110);//5
g.drawString(“National mosque”, 20, 100);//6
g.drawString(“Merdeka stadium”, 195, 135);//7
g.drawString(“NationalHM”, 150, 90);//8
g.drawString(“Central market”, 65, 70);//9

//note
g.setColor(Color.black);
g.drawString(“A- Natina”, 50,390);
g.setColor(Color.black);
g.drawString(“Start node”, 80,410);

g.setColor(Color.blue);
g.fillRect(50,400, 20, 20);
g.setColor(Color.black);
g.drawString(“Start node”, 80,410);

g.setColor(Color.red);
g.fillOval(50,430, 20, 20);
g.setColor(Color.black);
g.drawString(“Destination node”, 80,440);

g.setColor(Color.green);
g.drawLine(50, 460, 60, 460);
g.setColor(Color.black);
g.drawString(“Shotest route”, 80,460);

if (step == 1) {
g.setColor(Color.green);

if(first == 1){
//8&2 2&1
g.drawLine(135, 85, 210, 40); //line 8&3
g.drawLine(60, 50, 210, 40); //line 1&3
}
else if(first == 2) {
g.drawLine(185, 110, 135, 85); //line 5&8
g.drawLine(310, 60, 185, 110); //line 2&5
}
else if(first == 3)
g.drawLine(135, 85, 210, 40); //line 8&3
else if(first == 4) {
g.drawLine(185, 135, 110, 160); //line 5&8
g.drawLine(185, 100, 185, 125);//line 5&7
g.drawLine(110, 80, 125, 75);//line 5&7
}
else if(first == 5)
g.drawLine(185, 110, 135, 85); //line 5&8
else if(first == 6){
g.drawLine(110, 80, 135, 85); //line 8&6
g.drawLine(100, 80, 40, 100); //line 8&6
}
else if(first == 7){
g.drawLine(185, 110, 135, 85); //line 5&8
g.drawLine(185, 110, 185, 135);//line 5&7
}
else if(first == 9){
g.drawLine(110, 80, 135, 85);

}

}

//draw the points
if(first == 1 || second == 1)
g.setColor(Color.red);

else
g.setColor(Color.black);
g.fillOval(50, 40, 20, 20); //point 1

if(first == 2 || second == 2)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(300, 50, 20, 20); //point 2

if(first == 3 || second == 3)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(200, 30, 20, 20); //point 3

if(first == 4 || second == 4)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(100, 150, 20, 20); //point 4

if(first == 5 || second == 5)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(175, 100, 20, 20); //point 5

if(first == 6 || second == 6)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(30, 100, 20, 20); //point 6

if(first == 7 || second == 7)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(175, 125, 20, 20); //point 7

if(first == 8 || second == 8)
g.setColor(Color.blue);
else
g.setColor(Color.blue);
g.fillRect(125, 75, 20, 20); //point 8

if(first == 9|| second == 9)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillOval(90, 80, 20, 20); //point 9

}

private int balls[] = new int [12];
private int lines[] = new int [14];
private int chosen = 0, count, first, second, step;
}

Advertisements

2 responses to “my work on discrete

  1. em..nape x tunjuk kan yang full version 2…glamour sket group kte cun sket.huhu…:p

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s