多线程问题 在介面上添加了一个TableScrollPane,又在其上添加了一个JdbTable,程序可以正常显示。我想把TableScrollPane扩展为多线程得,JdbTable却不能正常显示,问题出在那儿呢?请教高手! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是修改前得代码: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; }} 这是修改后的代码: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); }} java如何指定出端口? 如何获取jpanel上某一坐标点的颜色 怎么从 new JScrollPane(new JTextArea) 这里 把对应的 JTextArea取出来 好难的数组题目 JTable如何实现undo?请大家帮忙. 请问大家一下,现在用java 5.0的多么? 考试中遇到的几个问题,挺郁闷的,解释不了。 数组赋值代码怎么写? to needle(),我还个问题! javac HelloWord 1个错误求解 请教怎么在JTextArea中输出显示不同颜色的文字呢? 千人工程怎么样?从那出来的人都在做什么?
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;
}
}
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);
}
}