У меня есть JFrame
и Jpanel
над тем, в котором размещены various buttons
.so по нажатию кнопки Я назвал new class
, что also having containers placed in a Jpanel
.soЯ хочу show
, что new class panel
над main Jframe panel
. Как я могу это сделать?
И если мы используем в нем макет карты, то как я могу использовать это, как при нажатии кнопки, которую я назвалобъект нового класса.as
Card layout consider each component in a container as card and i want whole Jpanel as a card so is it possible to do that???
Можем ли мы сделать в нем 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());
//here used containers over that frame
and call it from main()
}
here is another class to manage category is
public class manageCategory
{
JPanel panel = new JPanel();
GridBagLayout gridbglayout = new GridBagLayout();
GridBagConstraints gridbgconstraint = new GridBagConstraints();
public manageCategory()
{
panel.setLayout(new BorderLayout());
// i have again here used containers placed with grid bag layout
}
}
Так что теперь я хочу, чтобы, поскольку я click on home button
использовал в mymain
классе, то panel
, который являетсяиспользуется в manageCategory()
должно быть displayed
на той же панели. и когда я снова нажимаю на кнопку home
, появляется mymain panel
. Как я могу это сделать ???