做两个css相同的div,每个div中包含一个按钮,一个div显示,一个div隐藏,当点击第一按钮时,该div隐藏,显示另一个div.
你点击按钮时把按钮加样式呗 document.getElementById('').style.display=none;
然后你可以控制文字的显示
你可以点击该按钮时,改变该按钮的文本(注意按钮并没有改变),效果就像改变了按钮一样。
Try this, shuold be fine:
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TwoButtonExample extends WindowAdapter implements MouseListener {
private Frame f;
private Panel a, b;
private CardLayout cardLayout;
public static void main(String[] args) {
new TwoButtonExample();
}
public TwoButtonExample(){
f = new Frame("Test");
a = new Panel();
b = new Panel();
Button b1 = new Button("下面的数字123");
Button b2 = new Button("上面的");
b1.addMouseListener(this);
b2.addMouseListener(this);
a.add(b1);
b.add(b2);
cardLayout = new CardLayout();
f.setLayout(cardLayout);
f.add(a, "First");
f.add(b, "Second");
cardLayout.show(f, "Second");
f.pack();
f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void mouseClicked(MouseEvent e) {
cardLayout.first(f);
b.setVisible(false);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}