简体   繁体   English

小程序中的摇摆组件不起作用

[英]Swing components in applet not working

When I add swing components to my applet, they don't show up. 当我将小部件添加到小程序中时,它们不会出现。 Sometimes if I move my mouse around some JButtons pop up(strange). 有时,如果我在一些JButton周围移动鼠标,会弹出(奇怪)。 I have a method paint(Graphics g){} and update(Graphics g){}, but even when I remove all the images and painting code, the components still don't appear. 我有一个方法paint(Graphics g){}和update(Graphics g){},但是即使我删除了所有图像和绘画代码,这些组件仍然没有出现。 Is this something normal that happens with applets, or am I making a mistake? Applet发生这种情况是否正常,还是我做错了?

I also had same problem, here is the solution that helped me: 我也有同样的问题,这是对我有帮助的解决方案:

In your paint(Graphics g) method to paint all containers properly use super.paint(g). 在您的paint(Graphics g)方法中,要正确绘制所有容器,请使用super.paint(g)。

Like: 喜欢:

void paint(Graphics g)

{

  super.paint(g);

 //code to draw something 

}

It's common not in applets, but also in Java program. 这在applet中并不常见,在Java程序中也很常见。 As far as I know, I meet with many cases like that due to the incompatibility issue. 据我所知,由于不兼容问题,我遇到了很多类似的情况。 When this thing happens, minimize a window and resize it and all the objects pop up as they should. 发生这种情况时,请最小化一个窗口并调整其大小,然后所有对象都会弹出。 I'm not sure whether there's a solution to that. 我不确定是否有解决方案。 I think there should be one. 我认为应该有一个。 This mostly happens when you have objects overlapping. 当对象重叠时,通常会发生这种情况。

EDIT: Information maybe useful: When a window is resized in a regular java program, javax.swing.JComponent.repaint() is called. 编辑:信息可能有用:在常规Java程序中调整窗口大小时,将调用javax.swing.JComponent.repaint()。

Ok, I figured it out. 好的,我知道了。 Stupid mistake by me. 我的愚蠢错误。 I was using Applet, not JApplet. 我使用的是Applet,而不是JApplet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM