0

for ループがあり、次の 3 日間の気象条件を出力する API があります。

for (ForecastForday1 day : forecast) 
          {
            // Print out what day the forecast is for, and
            // the conditions on that day
            System.out.println("The weather on " + day.getDayOfWeek()
                   + " will be " + day.getInfo("Conditions"));
          }

しかし、私は3つのJTextAreaを持っているので、ループが繰り返されるたびにデータを1つのテキスト領域に配置し、次に次のテキスト領域にデータを配置します。

私のテキストエリア:

day1.append("");
day2.append("");
day3.append("");

したがって、このループにループを配置する必要があると思いますが、どこから始めればよいかわかりません。

4

4 に答える 4

1

これについて考えられる多くの方法の中から 1 つの方法を提案できます。

    int i=0;   
    for (ForecastForday1 day : forecast) 
                  {
                    if (i%3==0)
                       day1.append("string here");
                    else if (i%3==1)
                       day2.append("string here");
                    else if (i%3==2)
                       day3.append("string here");

                    i++;
                    // Print out what day the forecast is for, and
                    // the conditions on that day
                    System.out.println("The weather on " + day.getDayOfWeek()
                           + " will be " + day.getInfo("Conditions"));
                  }

これがあなたが望むものだと思います。

于 2013-03-31T06:25:00.333 に答える