关于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 阅读 9 次 更新于 2025-07-18 19:17:40 我来答关注问题0
  • 把所有小的按钮都放在显示区域, enable属性都设置成 false 在大按钮的onclick事件里让要显示的小按钮的enable属性设置成true;不显示的按钮,继续设置成 false...不知道我这样说你明白没

  •  wochen112 求java图形界面树类编程源码举例。类似windows资源管理器那样的。如附图,2层2项即可。

    treeNode2.add(treeNode2_

  •  文暄生活科普 Java图形界面设计之GridBagLayout使用心得

    学习Java编程,特别是开发图形界面时,我选择了Swing和Awt包。在跨平台和保证程序可移植性的需求下,放弃了绝对布局,转而探索GridBagLayout布局管理器的使用。通过查阅资料和实践,我逐渐掌握了GridBagLayout的基本用法。首先,创建Java Project,新建名为Guitest的类。导入Swing和Awt包,简化开发过程。在主函数...

  •  清正且奇巧的丁香 编写一个图形用户界面的Java Application 程序要求如下图求求了很着急

    import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;public class GUIApplication extends JFrame { public GUIApplication() { // 设置窗口标题 setTitle("Java Application");// 创建菜单栏 JMenuBar menuBar = new JMenuBar();// 创建文...

  •  好学者百科 怎样用java编写图形界面的Application程序?

    java编写图形界面需要用到swing等组件,可以在eclipse中安装windowbuilder来开发窗体,自动生成窗体代码,然后自己再根据需要修改,如:package mainFrame;import java.awt.EventQueue;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.ImageIcon;import javax.swing.JButton...

檬味博客在线解答立即免费咨询

报错相关话题

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