要不这么做, 能通过编译, 但没有结果, WHY?/*
* @(#)FirstApplet.java 1.0 04/12/08
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_2\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class FirstApplet extends Applet
{
private String s;
private Button button;
boolean y;
public void init()
{// Applet的大小在 html中调整
Button button = new Button("Hello");
button.addActionListener(new Handle());
this.add(button); // this -> Applet
s = "Welcome to Java!!";
} public void paint(Graphics g)
{
g.drawString(s, 50, 60 );
if (y)
button.setLabel("World");
else
button.setLabel("Java");
}
private class Handle implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
s = "Hello World!";
y = (!y);
repaint(); // 重新绘制 Applet 组件
}
}
}
* @(#)FirstApplet.java 1.0 04/12/08
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_2\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class FirstApplet extends Applet
{
private String s;
private Button button;
boolean y;
public void init()
{// Applet的大小在 html中调整
Button button = new Button("Hello");
button.addActionListener(new Handle());
this.add(button); // this -> Applet
s = "Welcome to Java!!";
} public void paint(Graphics g)
{
g.drawString(s, 50, 60 );
if (y)
button.setLabel("World");
else
button.setLabel("Java");
}
private class Handle implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
s = "Hello World!";
y = (!y);
repaint(); // 重新绘制 Applet 组件
}
}
}
解决方案 »
- JComboBox出现空异常
- 遇到一个开发问题,寻求解决办法
- 我想实现一个流的输入输出,看书看了半天啦,东凑西凑凑出个程序,可是不能实现,5555555555555555,晕死了。谁能帮我看看
- 人民币200+ 求助java一简单进程问题
- 请教JAVA国际化
- 请问java能不能调用perl写的程序?
- 捆饶好几天的一个问题好象是验证的问题!很奇怪!
- 为什么打印不出"\b"啊
- 如何获得Java的帮助啊
- 我想在JAVA中调用VC++的东西,怎么做?当然,这个系统只能在WINDOWS跑。
- 进者有分,问一个设计模式上的问题,大家参与讨论,在工程中很实用,关于CONNECTION每次用完后要关闭的问题,看谁能把这个问题复用封装的最好
- 100分求答,很简单的
你想用s来绘制标签只有用JApplet来做,这样是可以的
用JApplet
要传对象过来哦!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;public class FirstApplet extends Applet
{
private String s;
private Button button;
public void init()
{// Applet的大小在 html中调整
Button button = new Button("Hello");
button.addActionListener(new Handle(this));
this.add(button); // this -> Applet
s = "Welcome to Java!!";
} public void paint(Graphics g)
{
g.drawString(s, 50, 60 );
}
private class Handle implements ActionListener
{ public Handle(FirstApplet you)
{
this.you=you;
}
public void actionPerformed(ActionEvent e)
{
s = "Hello World!";
button.setLabel("World"); // 我这么设置, 错在哪里??
repaint(); // 重新绘制 Applet 组件
}
}
}
{
FirstApplet you;
public Handle(FirstApplet you)
{
this.you=you;
}
public void actionPerformed(ActionEvent e)
{
s = "Hello World!";
you.button.setLabel("World"); // 我这么设置, 错在哪里??
repaint(); // 重新绘制 Applet 组件
}
}
}
Handle(Applet p){myApplet = p;}
……},FirstApplet类中Button.addActionListener(new Handle(this));