//Yonatan Kelib
//Free Press in Africa
//ICM Final Version 2
import java.awt.Label;
import java.awt.Color;
import java.awt.*;
import javax.swing.*;
public class free_press_final extends PApplet implements ActionListener{
PImage map0; //declares the image of Africa.
PImage imageName;
String sCurrentCountry = "";
//declare each yes and no vote for each country so that the vote results will
//remain independent as the end user votes for each country.
int SAyesvote=0; //declares the yes for South Africa.
int SAnovote=0; //declares the no vote for South Africa.
int Maliyesvote=0; //declares the yes vote for Mali.
int Malinovote=0; //declares the no vote for Mali.
int Chadyesvote=0; //declares the yes vote for Chad.
int Chadnovote=0; //declares the no vote for Chad.
int Eriyesvote=0; //declares the yes vote for Eritrea.
int Erinovote=0; //declares the no vote for Eritrea.
int Conyesvote=0; //declares the yes vote for D.R Congo.
int Connovote=0; //declares the no vote for D.R Congo.
int MAX_IN_ARRAY = 8; //declares the max of arrays and set the max to 8.
int numberFound = 0; //declares numberFound.
int numberFound2 = 0;
int numberFound3 = 0;
int numberFound4 = 0;
int numberFound5 = 0;
String word; //string to get info for South Africa.
String dream="";
String country = "";
String countrys;
String[] country2 = new String[MAX_IN_ARRAY];
ArrayList listCountrys=new ArrayList();
String word2; //string to get info for Mali.
String dream2="";
String mali;
String malis;
String[] mali2 = new String[MAX_IN_ARRAY];
ArrayList listMali=new ArrayList();
String word3; //string to get info for Chad.
String dream3="";
String chad;
String chads;
String[] chad2 = new String[MAX_IN_ARRAY];
ArrayList listChad=new ArrayList();
String word4; //string to get info for Congo.
String dream4="";
String congo;
String congos;
String[] congo2 = new String[MAX_IN_ARRAY];
ArrayList listCongo=new ArrayList();
String word5; //string to get info for Eritrea.
String dream5="";
String eritrea;
String eritreas;
String[] eritrea2 = new String[MAX_IN_ARRAY];
ArrayList listEritrea=new ArrayList();
Button Yes = new Button ("Yes");
Button No= new Button("No");
Label myCountry = new Label();
Label mySurvey = new Label();
Label myResults = new Label();
int count = 0;
void setup(){
size(900,550); //sets the screen size of the window.
map0 = loadImage("background.jpg"); //map of africa.
background(#FFFFFF); //colors the background white.
myCountry.setLocation(500,20); //this sets up the table on the right hand side of the screen to display country information.
myCountry.setSize(350,200);
add(myCountry);
mySurvey.setLocation(500,220); //this sets up the table on the right hand side of the screen to display survey information.
mySurvey.setSize(350,50);
add(mySurvey);
mySurvey.setVisible(false);
Yes.setLocation(500, 310); //this sets up the position of the Yes button.
Yes.setSize(50,30);
Yes.addActionListener(this);
add(Yes);
Yes.setVisible(false);
println("Y vis false");
No.setLocation(560, 310); //this sets up the position of the No button.
No.setSize(50,30);
No.addActionListener(this);
add(No);
No.setVisible(false);
println("N vis false");
myResults.setLocation(500,420); //this sets up the diplay area of the results.
myResults.setSize(350,200);
add(myResults);
imageName = map0; //calls in the background image of Africa.
}
void draw(){
image(imageName,0,0);
stroke(255, 0, 0);
}
void mousePressed(){ //if the mouse is pressed begin the process of getting info and display appropriate text and survey information for South Africa.
if((250 < mouseX) && (mouseX < 350) && (450 < mouseY) && (mouseY < 525)){
getxml();
myResults.setText("");
Yes.setVisible( true);
No.setVisible(true);
survey();
mySurvey.setVisible(true);
myCountry.setText( word);
}
else //if the mouse is pressed begin the process of getting info and display appropriate text and survey information for Mali.
if((40 < mouseX) && (mouseX < 150) && (80 < mouseY) && (mouseY < 180)){
getmali();
myResults.setText("");
Yes.setVisible( true);
No.setVisible(true);
survey();
mySurvey.setVisible(true);
myCountry.setText( word2);
}
else //if the mouse is pressed begin the process of getting info and display appropriate text and survey information for Chad.
if((220 < mouseX) && (mouseX < 300) && (100 < mouseY) && (mouseY < 200)){
getchad();
myResults.setText("");
Yes.setVisible( true);
No.setVisible(true);
survey();
mySurvey.setVisible(true);
myCountry.setText( word3);
}
else //if the mouse is pressed begin the process of getting info and display appropriate text and survey information for Congo.
if((250 < mouseX) && (mouseX < 340) && (240 < mouseY) && (mouseY < 340)){
getcongo();
Yes.setVisible( true);
No.setVisible(true);
survey();
mySurvey.setVisible(true);
myCountry.setText( word4);
}
else //if the mouse is pressed begin the process of getting info and display appropriate text and survey information for Eritrea.
if((390 < mouseX) && (mouseX < 440) && (135 < mouseY) && (mouseY < 160)){
geteritrea();
myResults.setText("");
Yes.setVisible( true);
survey();
mySurvey.setVisible(true);
No.setVisible(true);
myCountry.setText( word5);
}
}
void getxml(){ //gets the info from sweetsoul.com/info.txt for South Africa.
myResults.setText("");
sCurrentCountry = "South Africa";
numberFound = 0;
String url = "http://www.sweetsoul.com/info.txt";
String[] slines = loadStrings(url);
String xml = "";
// Combines the entire array into one long string
for (int i = 0; i < slines.length; i++) {
xml += slines[i];
}
// Searchs for the words between the two points of country1 and /country1
String lookfor = "";
int startLookingAt = 0;
while(true){
int start = xml.indexOf(lookfor,startLookingAt);
if (start == -1) {
break; //stops the repeat loop;
}
int end = xml.indexOf("",start+lookfor.length());
country = xml.substring(start+10,end);
println("country is " + country);
//ArrayList brings in the words
listCountrys.add(country);
println("listWords here "+listCountrys);
country2[numberFound] = (xml + countrys);
numberFound++;
startLookingAt = end + 1;
if (numberFound >= MAX_IN_ARRAY) {
break; //stops the repeat loop;
}
}
word= "";
for (int g=0;g",start+lookfor.length());
mali = xml.substring(start+10,end);
println("country is " + mali);
//ArrayList brings in the word choices
listMali.add(mali);
println("listWords here "+listMali);
mali2[numberFound2] = (xml + malis);
numberFound2++;
startLookingAt = end + 1;
if (numberFound2 >= MAX_IN_ARRAY) {
break; //stops the repeat loop;
}
}
word2 = "";
for (int g=0;g",start+lookfor.length());
chad = xml.substring(start+10,end);
println("country is " + chad);
//ArrayList brings in the word choices
listChad.add(chad);
println("listWords here "+listChad);
chad2[numberFound3] = (xml + chads);
numberFound3++;
startLookingAt = end + 1;
if (numberFound3 >= MAX_IN_ARRAY) {
break; //stops the repeat loop;
}
}
word3 = "";
for (int g=0;g",start+lookfor.length());
congo = xml.substring(start+10,end);
println("country is " + congo);
//ArrayList brings in the word choices
listCongo.add(congo);
println("listWords here "+listCongo);
congo2[numberFound4] = (xml + congos);
numberFound4++;
startLookingAt = end + 1;
if (numberFound4 >= MAX_IN_ARRAY) {
break; //stops the repeat loop;
}
}
word4 = "";
for (int g=0;g",start+lookfor.length());
eritrea = xml.substring(start+10,end);
println("country is " + eritrea);
//ArrayList brings in the word choices
//println("where is this damm text:" + eritrea + '\n');
listEritrea.add(eritrea);
println("listWords here "+listEritrea);
eritrea2[numberFound5] = (xml + eritreas);
numberFound5++;
startLookingAt = end + 1;
if (numberFound5 >= MAX_IN_ARRAY) {
break; //stops the repeat loop;
}
}
word5 = "";
for (int g=0;g