在java中与JList一起使用Yahoo Finance API

在java中与JList一起使用Yahoo Finance API,java,netbeans,converter,Java,Netbeans,Converter,上周,我尝试用java的Yahoo finance API制作一个货币转换器,并在其中添加了一个JList 设置雅虎金融的所有货币。因此,我需要正确的源代码来实现这一点 我已经编写了以下代码: if (jList1.getSelectedValue() == null || jList2.getSelectedValue() == null) { jOptionPane1.showMessageDialog(null, "Please select a currency !");

上周,我尝试用java的Yahoo finance API制作一个货币转换器,并在其中添加了一个JList

设置雅虎金融的所有货币。因此,我需要正确的源代码来实现这一点

我已经编写了以下代码:

if (jList1.getSelectedValue() == null || jList2.getSelectedValue() == null) {
        jOptionPane1.showMessageDialog(null, "Please select a currency !");
    }

    //-----------------------------------------------stop the"re-------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------------------------------
    String curAmountText = jTextField1.getText();
   // Check for numbers only
   for(int i=0;i < curAmountText.length();i++)
   {
       if(!Character.isDigit(curAmountText.charAt(i)))
       {
           JOptionPane.showMessageDialog(this, "Please enter a valid amount!");
           jTextField1.requestFocus();
           return;
       }
   }
   String curFromText   = jList1.getSelectedValue().toString();
   String curToText     = jList2.getSelectedValue().toString();

   String[] temp = null;
   temp = curFromText.split(" - ");
   String curFromTitle = temp[0];
   String curFromCode = temp[1];

   temp = curToText.split(" - ");
   String curToTitle = temp[0];
   String curToCode = temp[1];

   String URL = "http://finance.yahoo.com/q/bc?s=" + curFromCode + "" + curToCode + "=X&t=5d&l=on&z=m&q=l&c=";

    try {
        // Fetch results from Yahoo
        String results = "";
        URL thePage = new URL(URL);
        BufferedReader in = new BufferedReader(new InputStreamReader(thePage.openStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
          // Process each line.
          results = results + inputLine;
        }
        in.close();
        // Parrent matching
        Pattern finalPattern = Pattern.compile("x\">([0-9.]+)</span>");
        Matcher matchFind = finalPattern.matcher(results);
        matchFind.find();

        double curRate = Double.valueOf(matchFind.group(1)).doubleValue();
        double totalConvert = curRate * Double.valueOf(jTextField1.getText()).doubleValue();

        // Trade Time Matching
        finalPattern = Pattern.compile("<span id=\"yfs_t10_[a-zA-Z]+=x\">(.*)</span>:");
        matchFind = finalPattern.matcher(results);
        matchFind.find();

        jTextField2.setText(String.format("%,.2f", totalConvert));
        jLabel9.setText("Per Trade Time: "+matchFind.group(1));
   } catch (Exception e) {
       // Do error handling
       JOptionPane.showMessageDialog(this, "Unable to connect to Yahoo Finance!");
   } 

所以,请帮助我,谢谢

那么,你有什么问题?听起来你好像在问:有人帮我完成我的程序,这并不是一件容易在SO上获得好评的事情。不,我只想要yahoo finance的链接,以及如何在java中与JList一起使用它