在JApplet上分层对象(扩展JComponet) [英] Layering Objects (That extend JComponet) on JApplet
问题描述
我目前有一个JApplet,其中添加了两个都扩展JComponet的对象. 对象A基本上是一个大正方形,而对象B是一个小正方形,我需要对象B始终位于对象A的前面,但是我无法解决如何在JApplet中设置分层的方法. 当前,我正在使用以下代码,该代码将两个项目都添加并显示它们,但是有时对象A位于对象B的前面.
I currently have a JApplet within which I add two objects that both extend JComponet. Object A is basically a large square and object B is a small square, I need Object B to always be in front of Object A, however I cant work out how to set layering within the JApplet to do this. Current I am using the follow code, which adds both the items and displays them how I want however sometimes Object A is front of Object B.
public void init() {
add(myapplet, BorderLayout.CENTER);
resize(200, 400);
B = new Block(Color.green, 10, 10);
myapplet.add(B);
A = new Block(Color.red, 100, 100);
myapplet.add(A);
myapplet.addMouseListener(this);
startTimer();
}
推荐答案
您可能会看到 JLayeredPane
,见此处,或OverlayLayout
,见混合方法可能会提供更多的灵活性.
You might look at JLayeredPane
, seen here, or OverlayLayout
, seen here. Either should work in an applet, but this hybrid approach may offer additional flexibility.
这篇关于在JApplet上分层对象(扩展JComponet)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!