0
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class GUI extends JFrame {
private JButton reg;
private JButton custom;
private JButton custom2;
public GUI(){
super("Heartstone Arena Alpha 0.01");
setLayout(new FlowLayout());
reg = new JButton("Click Me");
add(reg);
Icon ACn = new ImageIcon(getClass().getResource("463.png"));
Icon ACg = new ImageIcon(getClass().getResource("463 (1).png"));
custom = new JButton("Custom", ACn);
custom.setRolloverIcon(ACg);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener {
public void actionPerformed(ActionEvent event) {
Icon An = new ImageIcon(getClass().getResource("Alexstrasza(303).png"));
custom2 = new JButton(" ", An);
custom2.setIcon(An);
custom2.setRolloverIcon(An);
}
}
這裏更換按鈕的代碼,我想要做的是有它的點擊時CUSTOM2更換定製。 我怎麼會去這件事嗎? 我嘗試使用定製=無效,然後添加(CUSTOM2);但它不顯示 PS:忽略註冊按鈕與另一個按鈕
您可以使用不同的聽衆和文本一個按鈕進行評論。但是,如果不適合,看['CardLayout'(http://docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html)所看到的這個[簡短的例子] (http://stackoverflow.com/a/5786005/418556)。 –
刪除自定義/清潔框架 - >添加自定義2 - >重繪框架 – lebryant
@lebryant不要忘了驗證和或包框架或更好的,只是沒有提及hackish的方法,除非必要(與卡片佈局 - 它沒有必要*)。 –