📄 trycardlayout.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; // Classes to handle events
public class TryCardLayout extends JApplet
implements ActionListener // For event handling
{
CardLayout card = new CardLayout(50,50); // Create layout
public void init()
{
Container content = getContentPane();
content.setLayout(card); // Set card as the layout mgr
JButton button; // Stores a button
for(int i = 1; i <= 6; i++)
{
content.add(button = new JButton("Press " + i), "Card" + i); // Add a button
button.addActionListener(this); // Add listener for button
}
}
// Handle button events
public void actionPerformed(ActionEvent e)
{
card.next(getContentPane()); // Switch to the next card
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -