Hello guys,
I am trying to do Convert money project by using GUI and I did by connected with Website but I am thinking to do it in different way by using Scnner which I put all currency money inside "NotePad" instead of read it from web. For example,
inside Notepad:
Euro - EUR 5.5
British Pound - GBP 6.3
United States Dollar - USD 3.75
Australian Dollar - AUD 8.9
Canadian Dollar - CAD 5.9
Swiss Franc - CHF 6.6
Chinese Yuan - CNY 8.5
Hong Kong Dollar - HKD 8.6
Indonesian Rupiah - IDR 33.5
-------------------------------------------
This the code I have:
//The How much to convert
String currentamountText =CurrentAmount.getText();
// check the number if it alright.
for(int i=0;i< currentamountText.length();i++){


if(!Character.isDigit(currentamountText.charAt(i)) ){

JOptionPane.showMessageDialog(this, "Please insert A number","Error", JOptionPane.ERROR_MESSAGE);

return;
}
}

theResultis.setText("");

//currency from and to
String currentfromtext= ConvertFrom.getSelectedItem().toString();
String convertto=Convertto.getSelectedItem().toString();


String[] temp=null;
temp= currentfromtext.split(" - ");
String currFromCode=temp[1];



temp=convertto.split(" - ");
String converttoCode=temp[1];
String URL = "http://finance.yahoo.com/q/bc?s=" + currFromCode + "" + converttoCode + "=X&t=5d&l=on&z=m&q=l&c=";
try
{
String result="";
URL thePage= new URL(URL);
BufferedReader in = new BufferedReader(new InputStreamReader(thePage.openStream()));

String InputLine;
while((InputLine=in.readLine())!=null)
{
result=result+InputLine;

}
in.close();

Pattern finalPattern = Pattern.compile("x\">([0-9.]+)</span>");
Matcher matchFind = finalPattern.matcher(result);
matchFind.find();
double curRate=Double.valueOf(matchFind.group(1)).doubleV alue();
double totalConvert=curRate*Double.valueOf(CurrentAmount. getText()).doubleValue();

theResultis.setText(String.format("%,.2f",totalCon vert));
}



catch(Exception e){

JOptionPane.showMessageDialog(this, "There is propblem with web connection ");//, "Error", JOptionPane.ERROR_MESSAGE
}