当前位置: 代码迷 >> J2SE >> 一个奇怪的setText有关问题
  详细解决方案

一个奇怪的setText有关问题

热度:237   发布时间:2016-04-24 15:38:28.0
一个奇怪的setText问题
我在一个外部类中有一个JLabel对象,想在内部类中修改其text属性,可是在内部类中得到的这个JLabel对象却处于invalid状态,请高手指点迷津!
代码如下:
import   java.awt.BorderLayout;
import   java.awt.Color;
import   java.awt.GridLayout;
import   java.awt.Toolkit;
import   java.awt.event.ActionEvent;
import   java.awt.event.ActionListener;
import   java.io.BufferedReader;
import   java.io.IOException;
import   java.io.InputStreamReader;
import   java.util.Timer;
import   java.util.TimerTask;

import   javax.swing.ImageIcon;
import   javax.swing.JButton;
import   javax.swing.JFrame;
import   javax.swing.JLabel;
import   javax.swing.JPanel;
import   javax.swing.JTextField;
import   javax.swing.SwingConstants;
import   javax.swing.border.LineBorder;
import   javax.swing.border.TitledBorder;

public   class   Repair   {

private   JLabel   l_state   =   new   JLabel();

private   JTextField   tf_ip;

private   JTextField   textField;

private   JTextField   tf_echoNum;

private   JTextField   tf_bytes;

private   JFrame   frame;

private   static   String   testHost   =   "202.204.48.66 ";

private   static   int   sendBytes   =   1;

private   static   int   echoNum   =   1;

private   static   int   repairFrequency   =   5000;

private   static   Repair   m_instance   =   null;

private   static   Timer   timer   =   new   Timer();

private   static   TimerTask   task   =   new   RepairTask();

/**
  *   Launch   the   application
  *  
  *   @param   args
  */
public   static   void   main(String   args[])   {
try   {
Repair   window   =   new   Repair();
window.frame.setVisible(true);
timer.scheduleAtFixedRate(task,   0,   Repair.getInstance()
.getRepairFrequency());
}   catch   (Exception   e)   {
e.printStackTrace();
}
}

/**
  *   Create   the   application
  */
private   Repair()   {
initialize();
}

public   static   Repair   getInstance()   {
if   (m_instance   ==   null)   {
synchronized   (Repair.class)   {
if   (m_instance   ==   null)   {
m_instance   =   new   Repair();
}
}
}
return   m_instance;
}

/**
  *   Initialize   the   contents   of   the   frame
  */
private   void   initialize()   {
frame   =   new   JFrame();
frame.setResizable(false);
frame.setIconImage(new   ImageIcon( "tips.gif ").getImage());
frame.setTitle( "J.L网络修复器 ");
frame.setSize(308,   207);
frame.setLocation((int)   (Toolkit.getDefaultToolkit().getScreenSize()
.getWidth()   /   2   -   frame.getWidth()   /   2),   (int)   (Toolkit
.getDefaultToolkit().getScreenSize().getHeight()   /   2   -   frame
.getHeight()   /   2));