在介面上添加了一个TableScrollPane,又在其上添加了一个JdbTable,程序可以正常显示。我想把TableScrollPane扩展为多线程得,JdbTable却不能正常显示,问题出在那儿呢?请教高手!

解决方案 »

  1.   

    这是修改前得代码:
    package untitled2;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import com.borland.dbswing.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2006</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Applet1 extends Applet {
      private boolean isStandalone = false;
      XYLayout xYLayout1 = new XYLayout();
      TableScrollPane tableScrollPane1 = new TableScrollPane();
      JdbTable jdbTable1 = new JdbTable();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet1() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        this.setLayout(xYLayout1);
        this.add(tableScrollPane1, new XYConstraints(34, 25, 307, 84));
        tableScrollPane1.getViewport().add(jdbTable1, null);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }
    }
      

  2.   

    这是修改后的代码:
    package untitled2;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import com.borland.dbswing.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2006</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Applet1 extends Applet {
      private boolean isStandalone = false;
      XYLayout xYLayout1 = new XYLayout();
      ClassTablePane tableScrollPane1 = new ClassTablePane();  //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet1() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        this.setLayout(xYLayout1);
        this.add(tableScrollPane1, new XYConstraints(34, 25, 307, 84));  }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }
    }
    class ClassTablePane extends TableScrollPane implements Runnable
    {
      int i = 0;    //counter
      int sleepinterval = 200;//sleep interval. NOTE! keep it equal to sleepinterval@class ClassLineGraph
      boolean runthread = true;    //flag that control the running of the thread
      JdbTable jdbTable1 = new JdbTable();  Thread panelthread=null;
      public void start()
      {
        this.getViewport().add(jdbTable1, null);
        if (panelthread==null)
        {
          panelthread=new Thread (this);
          panelthread.start();
        }
      }  public void stop()
      {
        panelthread.stop();
        panelthread=null;
      }  public void run()
      {
         
        while(runthread)
        {
          repaint();   
          try{Thread.sleep(sleepinterval);}    //sleep
          catch(InterruptedException e){}
        }
      }
      public void repaint()
      {
        super.repaint();
      }
      public void paint(Graphics g)
      {
        super.paint(g);
      }
    }