我有一个JFrame和一个Jpanel,其中放置了各种按钮.所以点击一个按钮我已经调用了一个新类,它也有一个容器放在一个Jpanel.so我想在主要显示新的类面板Jframe面板.我怎么能这样做?
如果我们在其中使用卡片布局,那么我如何使用它作为点击按钮我已经调用了新类的对象.
如
卡布局考虑容器中的每个组件作为卡,我想要整个Jpanel作为卡,所以可以这样做???
我们可以在其中嵌套Jpanels吗?
请建议我这样做的正确方法?
这是SSCCE:
// this is the main class on which i want to use panel of other class
public class mymain
{
JFrame jframe = new JFrame();
JPanel panel = new JPanel();
BorderLayout borderlayout = new BorderLayout();
public mymain()
{
jframe.setLayout(borderlayout);
JMenuBar menubar = new JMenuBar();
jframe.setJMenuBar(menubar);
JButton home_button = new JButton("HOME");
menubar.add(home_button);
jframe.getContentPane().add(panel,BorderLayout.CENTER);
panel.setLayout(new GridBagLayout());</