当前位置: 技术问答>java相关
Think in java 源程序编译,满脸的畸形字符,最后出现一百个错误!!!!!
来源: 互联网 发布时间:2014-12-31
本文导语: import java.awt.*; import java.awt.event.*; import java.applet.*; class SeparateSubTask extends Thread { private int count=0; private Counter2 c2; private boolean runFlag=true; public SeparateSubTask(Counter2 c2) { this.c2=c2; start(); } public void inverFlag()...
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class SeparateSubTask extends Thread
{
private int count=0;
private Counter2 c2;
private boolean runFlag=true;
public SeparateSubTask(Counter2 c2)
{
this.c2=c2;
start();
}
public void inverFlag()
{
runFlag=!runFlag;
}
public void run()
{
while(true)
{try
{sleep(100);
}catch(InterruptedException e){}
if(runFlag)
c2.t.setText(Integer.toString(count++));
}
}
}
public class Counter2 extends Applet
{
TextField t=new TextField(10);
private SeparateSubTask sp=null;
private Button
onoff=new Button("Toggle"),
start=new Button("start");
public void init()
{
add(t);
start.addActionListener(new StartL());
add(start);
onoff.addActionLiatener(new OnOffL());
add(onoff);
}
class StartL implements ActionListener
{
public actionPerformed(ActionEvent e)
{
if(sp==null)
sp=new SeparateSubTask(Counter2.this);
}
}
class OnOffL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(sp!=null)
sp.invertFlag();
}
}
public static void main(String[] args)
{
Counter2 applet=new Counter2();
Frame aFrame=new Frame("Counter2");
aFrame.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
aFrame.add(applet,BorderLayout.CENTER);
aFrame.setSize(300,200);
applet.init();
applet.start();
aFrame.setVisible(true);
}
}
import java.awt.event.*;
import java.applet.*;
class SeparateSubTask extends Thread
{
private int count=0;
private Counter2 c2;
private boolean runFlag=true;
public SeparateSubTask(Counter2 c2)
{
this.c2=c2;
start();
}
public void inverFlag()
{
runFlag=!runFlag;
}
public void run()
{
while(true)
{try
{sleep(100);
}catch(InterruptedException e){}
if(runFlag)
c2.t.setText(Integer.toString(count++));
}
}
}
public class Counter2 extends Applet
{
TextField t=new TextField(10);
private SeparateSubTask sp=null;
private Button
onoff=new Button("Toggle"),
start=new Button("start");
public void init()
{
add(t);
start.addActionListener(new StartL());
add(start);
onoff.addActionLiatener(new OnOffL());
add(onoff);
}
class StartL implements ActionListener
{
public actionPerformed(ActionEvent e)
{
if(sp==null)
sp=new SeparateSubTask(Counter2.this);
}
}
class OnOffL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(sp!=null)
sp.invertFlag();
}
}
public static void main(String[] args)
{
Counter2 applet=new Counter2();
Frame aFrame=new Frame("Counter2");
aFrame.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
aFrame.add(applet,BorderLayout.CENTER);
aFrame.setSize(300,200);
applet.init();
applet.start();
aFrame.setVisible(true);
}
}
|
也能运行!
|
喊什么,我用就没问题,简单的一个线程程序,
|
看来你的java环境还是没有调好,我编译过你这段程序只有三四个小错误而已。
|
我是用jdk1.3编译的。