怪事:线程在没被触发时,自动运行?
import java.applet.*;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import *;
public class Revolve extends JApplet
implements Runnable,ActionListener{
String[] pageTitle=new String[6];
URL[] pageLink=new URL[6];
Color butterscotch=new Color(255,204,158);
int current=0;
Thread runner;
public void init(){
pageTitle[0]="网易";
pageLink[0]=getURL("http://www.);
pageTitle[1]="搜狐";
pageLink[1]=getURL("http://www.);
pageTitle[2]="腾讯";
pageLink[2]=getURL("http://www.);
pageTitle[3]="新浪";
pageLink[3]=getURL("http://www.);
pageTitle[4]="雅虎";
pageLink[4]=getURL("http://www.);
pageTitle[5]="TOM";
pageLink[5]=getURL("http://www.);
Button goButton=new Button("Go");
goButton.addActionListener(this);
FlowLayout flow=new FlowLayout();
setLayout(flow);
add(goButton);}
URL getURL(String urltext){
URL pageURL=null;
try{pageURL=new URL(getDocumentBase(),urltext);
}catch(MalformedURLException m){}
return pageURL;
}
public void paint(Graphics screen){
Graphics2D screen2D=(Graphics2D)screen;
screen2D.setColor(butterscotch);
screen2D.fillRect(0,0,getSize().width,getSize().height);
screen2D.setColor(Color.red);
screen2D.drawString(pageTitle[current],5,60);
screen2D.drawString(""+pageLink[current],5,80);
}
public void start(){
if(runner==null){
runner=new Thread(this);
runner.start();}}
public void run(){
Thread thisThread=Thread.currentThread();
while(runner==thisThread){
current++;
if(current>5){current=0;}
repaint();
try{Thread.sleep(10000);}
catch(InterruptedException e){}}}
public void stop(){
if(runner!=null){
runner=null;}}
public void actionPerformed(ActionEvent evt){
if (runner!=null){
runner=null;}
AppletContext browser=getAppletContext();
if(pageLink[current]!=null){
browser.showDocument(pageLink[current]);}}}
1.请问线程在什么地方被触发了?个人认为在INIT()函数中,没有线程开始的语句,但线程却在程序一开始就运行了?
2.screen2D.setColor(butterscotch);
screen2D.fillRect(0,0,getSize().width,getSize().height);
screen2D.setColor(Color.red);在这里,第一个SETCOLOR用来设置背景颜色,第二个用来设置字体颜色,请问系统如何识别这两条语句的,怎么知道一条是用来设置背景,另一条是用来设置字体的?