代码如下:
import java.awt.*; public class GraphicsAppletInOut
{
public static void main(String args[])
{
AppletFrame MyFrame = new AppletFrame();
}
}class AppletFrame extends Frame
{
Label prompt;
TextField input;
Label output;
AppletFrame()
{
super("Application Graphics Frame");
setLayout(new FlowLayout());
prompt = new Label("Enter a character please:");
input = new TextField(4);
output = new Label(" ");
add(prompt);
add(input);
add(output);
pack();
show();
}
}public boolean action(Event e,Object o)
{
output.setText("You've entered character "+o.toString());
return true;
}public boolean handleEvent(Event e)
{
if(e.id == Evend.WINDOWN_DESTROY)
System.exit(0);
return super.handleEvent(e);
}
然后编译
javac GraphicsAppletInOut.java
GraphicsAppletInOut.java:32:''class' or 'interface' expected public boolean action(Event e,Object o)请问哪里出错了,小弟是新手,刚学java不久
先谢过了
import java.awt.*; public class GraphicsAppletInOut
{
public static void main(String args[])
{
AppletFrame MyFrame = new AppletFrame();
}
}class AppletFrame extends Frame
{
Label prompt;
TextField input;
Label output;
AppletFrame()
{
super("Application Graphics Frame");
setLayout(new FlowLayout());
prompt = new Label("Enter a character please:");
input = new TextField(4);
output = new Label(" ");
add(prompt);
add(input);
add(output);
pack();
show();
}
}public boolean action(Event e,Object o)
{
output.setText("You've entered character "+o.toString());
return true;
}public boolean handleEvent(Event e)
{
if(e.id == Evend.WINDOWN_DESTROY)
System.exit(0);
return super.handleEvent(e);
}
然后编译
javac GraphicsAppletInOut.java
GraphicsAppletInOut.java:32:''class' or 'interface' expected public boolean action(Event e,Object o)请问哪里出错了,小弟是新手,刚学java不久
先谢过了
import java.awt.*; public class GraphicAppletInOut
{
public static void main(String args[])
{
AppletFrame MyFrame = new AppletFrame();
}
}class AppletFrame extends Frame
{
Label prompt;
TextField input;
Label output;
AppletFrame()
{
super("Application Graphics Frame");
setLayout(new FlowLayout());
prompt = new Label("Enter a character please:");
input = new TextField(4);
output = new Label(" ");
add(prompt);
add(input);
add(output);
pack();
show();
}public boolean action(Event e,Object o)
{
output.setText("You've entered character "+o.toString());
return true;
}public boolean handleEvent(Event e)
{
if(e.id == e.WINDOW_DESTROY)
System.exit(0);
return super.handleEvent(e);
}
}
有个情况想说一下,这个程序是书上的,我安装的是j2sdk1.4.2_13(因为这本书出来的时候,还没j2sdk1.5.0)。
在提问之前,我已经在baidu和google上搜索了一下,但没有答案。
Note:GraphicAppletInOut.java uses or overrides a deprecated API.
Note:Recompile with -deprecation for details
show()改成setVisible(true)试试看
}
}
把第二个}放到这个文件的最后一行然后就可以成功编译了,并可以运行了。(尽管中间出现了警告:使用了过时的API)
方法是应该放在类或者接口中的,不可以单独例出来..
想想怎么讲的..java程序是由类组成的...而不action(){}函数直接构成的..