[英]Problem with Java Applet
I'm new to Java Applet
s. 我是Java
Applet
的新手。 I have a problem while reloading the applet. 重新加载小程序时出现问题。 When I resize the applet window or open some other application and then come back to the applet, the contents on the screen is redrawn.
当我调整applet窗口的大小或打开某些其他应用程序然后返回applet时,屏幕上的内容将重新绘制。 Basically my
paint
method is getting called. 基本上我的
paint
方法被调用了。 I want the contents of the paint
method to be called only once. 我希望
paint
方法的内容仅被调用一次。 How can I accomplish this? 我该怎么做? Can anyone please help me with this?
谁能帮我这个忙吗?
Thanks in advance. 提前致谢。
You are misunderstanding how paint
works - you have no real control over how many times it is called. 您误解了
paint
工作原理-您无法真正控制paint
调用次数。 What are you doing in the paint
method that makes you think you only want to do it once and why is it a problem that it gets called again? 您在
paint
方法中正在做什么,使您认为您只想执行一次,为什么再次调用它会带来问题?
If you're worrying about flickering, then you might like to look at painting into a buffer . 如果您担心闪烁,那么您可能想看看在缓冲区中绘画。 Code not directly related to painting should not be in the
paint
method. 不直接相关的绘制代码不应该是在
paint
的方法。 You can put other initialization logic in the applet's start
method 您可以将其他初始化逻辑放入applet的
start
方法中
If you're putting initialization code into the paint method, you might think about putting it into the init or start methods instead. 如果要将初始化代码放入paint方法中,则可以考虑将其放入init或start方法中。
The phrase you'd be looking for is applet lifecycle . 您要查找的短语是applet生命周期 。
I am new to java applet design and when running it i get one problem that says "no main" 我是Java applet设计的新手,运行它时出现一个问题,提示“无主程序”
here is my code: 这是我的代码:
import java.applet.*;
import java.awt.*;
public class abhidev extends Applet {
/** Initializes the applet abhidev */
public void init() {
try {
setBackground(Color.cyan);
}
catch(Exception e){
e.printStackTrace();
}
}
public void paint(Graphics g){
try{
g.drawString("this ais an applet window",10,30);
showStatus("this is astatus window");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
The applet class name is: abhidev.java. 小程序的类名称为:abhidev.java。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.