标题:在 Frame 中添加两个 Panel,如何切换
只看楼主
yuxiaoyanyry
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2014-9-13
结帖率:90.91%
已结贴  问题点数:14 回复次数:2 
在 Frame 中添加两个 Panel,如何切换
在一个frame上加了两个Panel,他们都和frame一样大小,我想点击菜单,然后进行切换,怎么做啊?
搜索更多相关主题的帖子: frame 如何 
2014-10-30 17:08
liucao
Rank: 10Rank: 10Rank: 10
来 自:恶灵之城
等 级:贵宾
威 望:13
帖 子:538
专家分:1575
注 册:2014-8-6
得分:4 
没懂,private JPanel p, p1, p2, p3;这样去写不行么,点击菜单只是有下拉选项吧,你要做的是什么啊

one car come one car go ,two car peng peng people die.
2014-10-31 16:06
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
得分:10 
程序代码:
package thread_437890;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JPanelTest extends JFrame {
    JButton jbutton1 = new JButton("设置成绿色");
    JButton jbutton2 = new JButton("设置成蓝色");
    JPanel jpanel = new JPanel();
    JPanel jpane2 = new JPanel();
    JPanel contentPane = new JPanel();

    public JPanelTest() {
        jbutton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                contentPane.remove(jpanel);
                contentPane.add(jpane2);
                contentPane.revalidate();
                contentPane.repaint();
                }
            });
        jbutton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                contentPane.remove(jpane2);
                contentPane.add(jpanel);
                contentPane.revalidate();
                contentPane.repaint();
                }
            });

        jpanel.add(jbutton1);
        jpanel.setBackground(Color.BLUE);
        jpanel.setPreferredSize(new Dimension(600, 400));
        
        jpane2.add(jbutton2);
        jpane2.setBackground(Color.GREEN);
        jpane2.setPreferredSize(new Dimension(600, 400));

        setBounds(0, 0, 640, 480);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.add(jpanel);
        setContentPane(contentPane);
        setVisible(true);
    }

    public static void main(String[] args) {
        new JPanelTest();
    }
}
2014-11-01 11:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-437890-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.767511 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved