我想要做的就是設置卡片佈局樣式按鈕。從理論上講,你應該點擊按鈕,另一個(在這種情況下)名字會被假設出來直到完成。 (當用戶關閉)試圖讓cardLayout工作
我有這樣的,我覺得它應該TOTALLY工作,但JGrasp是給我的錯誤:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDisappearingFriends extends JFrame implements ActionListener
{
private JButton intro = new JButton("Click to see Friends!");
private JButton nb = new JButton("Mini Vinny");
private JButton sb = new JButton("Makayla");
private JButton eb = new JButton("Aurora");
private JButton wb = new JButton("Alyssa");
private JButton cb = new JButton("And My Bestest Friend: SAMMY!!");
CardLayout cardLayout = new CardLayout();
public JDisappearingFriends()
{
setLayout(new CardLayout());
add("Click to see Friends!", intro);
add("MiniVinny", nb);
add("Makayla", sb);
add("Aurora", eb);
add("Alyssa", wb);
add("And Finally My Best Friend Sammy!", cb);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
intro.addActionListener(this);
nb.addActionListener(this);
sb.addActionListener(this);
eb.addActionListener(this);
wb.addActionListener(this);
}
public void actionPreformed(ActionEvent e)
{
cardLayout.next(getContentPane());
}
public static void main(String[] args)
{
JDisappearingFriends jbl = new JDisappearingFriends();
jbl.setSize(400, 400);
jbl.setVisible(true);
}
}
當我嘗試編譯,我得到一個錯誤信息,上市如下:
JDisappearingFriends.java:8: error: JDisappearingFriends is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
公共類JDisappearingFriends擴展JFrame中實現的ActionListener ^ 如果任何人都可以把我一個提示,我將不勝感激!
HAHAHAHAhahahaha OMG謝謝你sooo,我簡直不敢相信那麼簡單!過分看起來像是瘋狂!謝謝,現在我可以停止擊中我的頭在鍵盤上! –
@Stuckonsameproblem哦,我不知道,我發現我的頭對着鍵盤的包裝往往寫更好的代碼;) – MadProgrammer