关于JAVA图形界面的编程

把所有小的按钮都放在显示区域, enable属性都设置成 false 在大按钮的onclick事件里让要显示的小按钮的enable属性设置成true;不显示的按钮,继续设置成 false...不知道我这样说你明白没 import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Hello extends JFrame{private J...
关于JAVA图形界面的编程
感觉你要做的是一个级联菜单一样...
把所有小的按钮都放在显示区域, enable属性都设置成 false
在大按钮的onclick事件里让要显示的小按钮的enable属性设置成true;不显示的按钮,继续设置成 false...不知道我这样说你明白没2008-03-26
用JTabbedPane撒2008-03-27
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Hello extends JFrame{

private JButton button1=new JButton("1");
private JButton button2=new JButton("2");
private JButton button3=new JButton("3");

private JButton [] button =new JButton[4];

public Hello(){
Container c=this.getContentPane();
c.setLayout(new BorderLayout(10,30));

//northPanel
JPanel northPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,20,0));
northPanel.add(button1);
northPanel.add(button2);
northPanel.add(button3);
button1.addActionListener(new ButtonOperation());
button2.addActionListener(new ButtonOperation());
button3.addActionListener(new ButtonOperation());

c.add(northPanel,BorderLayout.NORTH);

//centerPanel
JPanel centerPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,20,0));
for(int i=0;i<button.length;i++){
button[i]=new JButton("");
button[i].setVisible(false);
centerPanel.add(button[i]);
}

c.add(centerPanel,BorderLayout.CENTER);

this.setSize(500, 400);
this.setVisible(true);
}

private class ButtonOperation implements ActionListener{
public void actionPerformed(ActionEvent event){
if(event.getSource()==button1){ //click button1
for(int i=0;i<button.length;i++){
if(i==0){
button[0].setText("1_1");
button[0].setVisible(true);
}

else button[i].setVisible(false);

}
}

if(event.getSource()==button2){ //click button2
for(int i=0;i<button.length;i++){
if(i==1||i==2){
button[i].setText("2_"+(i+1));
button[i].setVisible(true);
}

else button[i].setVisible(false);
}
}

if(event.getSource()==button3){ //click button3
for(int i=0;i<button.length;i++){
button[i].setText("3_"+(i+1));
button[i].setVisible(true);
}
}
}
}
public static void main(String[] args) {
new Hello();

}

}2008-03-27
mengvlog 阅读 55 次 更新于 2025-10-30 00:11:52 我来答关注问题0
檬味博客在线解答立即免费咨询

报错相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部