如何在循环中更改字体的颜色?

时间:2014-10-04 00:38:06

标签: java loops fonts colors jtextfield

我正在研究一个功能性的召回名单。一旦循环验证消息已发送,我希望更改电话号码的字体颜色。我似乎无法让字体改变颜色,我只得到错误1错误和28个警告:

*错误*

File: C:\Users\Jubear\Desktop\Recall\AddressBook.java  [line: 818]
Error: The method setForeground(java.awt.Color) is undefined for the type java.lang.String

代码:

   public void doRecall() {
      newFrame = new JFrame("All Contacts In The Address Book");
      newFrame.setSize(600, 300);
      newFrame.setIconImage(img);
      Contact con = new Contact();
      String columnNames[] = { "First Name", "Last Name", "Nickname",
            "E Mail Address", "Address", "Phone No.", "Webpage", "B'day" };
      Object data[][] = new Object[v.size()][8];
      for (int j = 0; j < v.size(); j++) {
         con = (Contact) v.elementAt(k);
         data[j][0] = con.getFName();
         data[j][1] = con.getLName();
         data[j][2] = con.getNname();
         data[j][3] = con.getEMail();
         data[j][4] = con.getAddress();
         data[j][5] = con.getPhoneNo();
         data[j][6] = con.getWebpage();
         data[j][7] = con.getBday();
         k++; // ??? what the hell is k???
      }
      k = 0;
      JTable abtable = new JTable(data, columnNames);
      JScrollPane scrollPane = new JScrollPane(abtable);
      abtable.setPreferredScrollableViewportSize(new Dimension(500, 370));
      JPanel pane = new JPanel();
      JLabel label = new JLabel("Initiating Total Recall");
      pane.add(label);
      newFrame.getContentPane().add(pane, BorderLayout.SOUTH);
      newFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
      newFrame.setLocation(screenWidth / 4, screenHeight / 4);
      newFrame.show();
      for (int j = 0; j < v.size(); j++) {
         con = (Contact) v.elementAt(k);
         data[j][0] = con.getFName();
         data[j][1] = con.getLName();
         data[j][2] = con.getNname();
         data[j][3] = con.getEMail();
         data[j][4] = con.getAddress();
         data[j][5] = con.getPhoneNo();
         data[j][6] = con.getWebpage();
         data[j][7] = con.getBday();
         try {
            String myPasscode = "*********";
            String myUsername = "*********";
            String toPhoneNumber = con.getPhoneNo();
            String requestUrl = ("http://cloud.fowiz.com/api/message_http_api.php?username=**********&phonenumber=+"
                  + toPhoneNumber + "&message=" + "hello" + "&passcode=******");
            URL url = new URL(requestUrl);
            HttpURLConnection uc = (HttpURLConnection) url.openConnection();
            System.out.println(uc.getResponseMessage());
            String reply = uc.getResponseMessage();
            // ///////////////////// HERE IS THE BROKEN CODE
            if (reply.equalsIgnoreCase("ok")) {
               con.getPhoneNo().setForeground(Color.RED);
            }
            // /////////////////////////////////////////////////
            uc.disconnect();
         } catch (Exception ex) {
            System.out.println(ex.getMessage());
         }
         k++;
      }
      k = 0;
   }

0 个答案:

没有答案
相关问题