java 模板 点击预览_Java中JFrame中我想点击不同菜单项的显示不同模板,为什么老是不行!!??...

我点击第一个就可以,点别的就不可以,哪里出错了?我用的是setVisible();JPanelp1=newJPanel();JPanelp2=newJPanel();JMenuItemfunction1,function2;JMenuBarmenubar;//菜单条JMenum...

我点击第一个就可以,点别的就不可以,哪里出错了?我用的是setVisible();

JPanel p1 = new JPanel(); JPanel p2 = new JPanel();

JMenuItem function1,function2;

JMenuBar menubar;//菜单条JMenu menu;//菜单

void init{

menubar = new JMenuBar();menu = new JMenu("显示");

function1 = new JMenuItem("显示一");

function2 = new JMenuItem("显示二");

menu.add(function1);menu.add(function2);

menu.addSeparator();menubar.add(menu);setJMenuBar(menubar);

JLabel mb1 = new JLabel("模板一:"); p1.add(mb1); information1 = new JTextField(5); p1.add(information1);

JLabel mb2= new JLabel("模板二:"); p2.add(mb2); score1 = new JTextField(5); p2.add(score1);

add(p1);

add(p2);

function1.addActionListener(this);

function2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) { if (e.getSource()==function1) { p1.setVisible(true);p2.setVisible(false); }else if (e.getSource()==function2) { p1.setVisible(false);p2.setVisible(true); }

}

很多代码没写出来,不够位置,弄了一点点上去!谢谢大神们!

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值