I am using Java CardLayout to switch between cards and JPanel. When activity starts in android I can use onLoad, or similar to check if the activity is now open. What is the equivalent to this in swing? How can I know if the JPanel (Card) is now in front?

public class FirstScreen extends JPanel 
{
//am I visible now?
}
有帮助吗?

解决方案

Implement windowActivated() in a WindowListener or WindowAdapter, as shown in How to Write Window Listeners and this example. See also How to Write a Component Listener.

Addendum: To receive notification that a particular card was selected, use a PropertyChangeEvent, as shown here, or an AncestorEvent, as shown here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top