我想在panel A上放置若干个子panel,这些子panel互不相同但都是从panel B继承的,panel A用到的方法都是在panel B中定义的(即没有用到在子panel中定义的方法)。因为在panel A上放置那些子panel是不定的,有没有办法能够不指定具体的子panel,来实现panel A对子panel的操作。
比如:能否在panel中定义panel B为其成员,然后在实例化的时候,创建B的子类的实例。
不知道有没有说清楚,谢谢了!
比如:能否在panel中定义panel B为其成员,然后在实例化的时候,创建B的子类的实例。
不知道有没有说清楚,谢谢了!
class ClassLinePlot extends ClassMultiThreadPanel
class ClassKrigingGraphic extends ClassMultiThreadPanel现在在另一个ClassPanel中需要定义ClassLinePlot或者ClassKrigingGraphic ,具体哪一个要运行时确定。
我在ClassPanel中定义
ClassMultiThreadPanel[] MultiThreadPanel = new ClassMultiThreadPanel[4];
然后根据传入的参数决定
是 for (int i = 0; i < 4; i++)
MultiThreadPanel[i] = new ClassLinePlot();
还是
for (int i = 0; i < 4; i++)
MultiThreadPanel[i] = new ClassKrigingGraphic ();结果报错java.lang.NoClassDefFoundError: ClassLinePlot at ClassPanel.<init>(iSnamp.java:266) at iSnamp.jbInit(iSnamp.java:79) at iSnamp.init(iSnamp.java:51) at com.borland.jbuilder.runtime.applet.AppletTestbed.startApplet(Unknown Source) at com.borland.jbuilder.runtime.applet.AppletTestbed.main(Unknown Source)Exception in thread "main" 请教大家
这跟多线程有关系吗?
有人知道吗?
{
int id;
int SleepInterval;//sleep interval.
boolean RunThread; //flag that control the running of the thread
boolean Visible;
Rectangle Bounds;
Thread PanelThread=null; ClassMultiThreadPanel()
{
id = 0;
SleepInterval = 100;
RunThread = true;
Visible = false;
Bounds = new Rectangle(0,0,400,250);
} ClassMultiThreadPanel(int sleepinterval, boolean runthread,
boolean visable, Rectangle bounds)
{
id = 0;
SleepInterval = sleepinterval;
RunThread = runthread;
Visible = visable;
Bounds = bounds;
} public void hide()
{
Visible = false;
} public void reveal()
{
Visible = true;
} public void runthread()
{
RunThread = true;
} public void stopthread()
{
RunThread = false;
} public void setSleepInterval(int sleepinterval)
{
SleepInterval = sleepinterval;
} public int getSleepInterval()
{
return SleepInterval;
}
public void start()
{
if (PanelThread==null)
{
PanelThread=new Thread (this);
PanelThread.start();
}
} public void stop()
{
PanelThread.stop();
PanelThread=null;
} public void run()
{
while(RunThread)
{
repaint(); //clear the canvas and repaint
try{Thread.sleep(SleepInterval);} //sleep
catch(InterruptedException e){}
}
}
public void repaint()
{
super.repaint();//important! clear the canvas
}
}
public ClassMultiThreadPanel (){
}
定义了,而且调用父类的super();
class ClassLinePlot extends ClassMultiThreadPanel
{
ClassSensorData SensorData; ClassLinePlot(int SensorDataType, int SensorNodeNum);
{
super();
SensorData = new ClassSensorData(SensorDataType,SensorNodeNum);
}
ClassLinePlot(int SleepInterval, boolean RunThread,
boolean Visable, Rectangle Bounds,
int SensorDataType, int SensorNodeNum);
{
super(SleepInterval, RunThread, Visable, Bounds);
SensorData = new ClassSensorData(SensorDataType,SensorNodeNum);
} void show(Graphics g, int id) //show the plot
{
//update data first!
//draw the line plot here!
} public void paint(Graphics g)
{
super.paint(g);
id++;
this.show(g,id); //show the line plot
}
}
http://post.baidu.com/f?kz=151350329
了
多谢!
ClassLinePlot(int SensorDataType, int SensorNodeNum);
汗,还是谢谢大家了。
使用到ClassCoordinateData
在你的代码里没找到这个类
注释掉
我能够跑起来