简体   繁体   English

如何定义jpanels到他们自己的类之间切换?

[英]How to define jpanels to their own class switching between them?

Currently making a program that is to access a sql database where the data is viewed on a Jtable with textfields and buttons on the side to alter add and delete data from the database (this is all working). 当前正在制作一个程序来访问sql数据库,在该数据库上可以在Jtable上查看数据,并在侧面查看文本字段和按钮以更改从数据库中添加和删除数据的方法(这一切都可以)。 What I'm troubled with is, I've started making my other jpanels, (currently using one class for all this) and I've found that the amount of lines of code is getting large.. 我遇到的麻烦是,我已经开始制作其他jpanel,(目前所有这些都使用一个类),并且发现代码行数量越来越大。

I would like to ask, is it possible define each jpanels content and buttons in their own separate class, and how I would go about doing so. 我想问一下,是否可以在自己的单独类中定义每个jpanel的内容和按钮,以及我将如何去做。 With that, how would I switch between each jpanel? 这样,如何在每个jpanel之间切换?

Currently using a cardlayout with different japanels. 当前正在使用具有不同JPY的卡片布局。 Heres how my UI looks, (not the main jpanel). 这是我的UI外观(不是主要的jpanel)。

在此处输入图片说明

The 5 buttons at the very top of the GUI is supposed to navigate between the jpanels, and the rest of the buttons, textfields and jtables differ depending on the jpanel thats navigated to. GUI顶部的5个按钮应该在jpanel之间导航,其余的按钮,文本字段和jtable取决于导航到的jpanel。

Some of the code within the main class, which has my jpanels: 主类中的一些代码,包含我的jpanels:

    JPanel main_panel = new JPanel();
    contentPane.add(main_panel, "name_21784032966449");
    main_panel.setLayout(null);

    JButton btnHome = new JButton("Home");
    btnHome.setBounds(10, 11, 97, 38);
    main_panel.add(btnHome);

    JButton btnHandOver = new JButton("Hand Over");
    btnHandOver.setBounds(117, 11, 97, 38);
    main_panel.add(btnHandOver);

    JButton btnMachineLogs = new JButton("Machine Logs");
    btnMachineLogs.setBounds(224, 11, 97, 38);
    main_panel.add(btnMachineLogs);

    JButton btnParts = new JButton("Parts");
    btnParts.setBounds(10, 60, 97, 38);
    main_panel.add(btnParts);

    JButton btnRunup = new JButton("Run Up");
    btnRunup.setBounds(117, 60, 97, 38);
    main_panel.add(btnRunup);

    JPanel parts_panel = new JPanel();
    contentPane.add(parts_panel, "name_22617526869296");
    parts_panel.setLayout(null);

I have no idea how to instead define each jpanel to their own classes, and less for how to make it possible to switch between panels. 我不知道如何将每个jpanel定义为自己的类,更不用说如何在面板之间切换了。

Thanks to hovercraft full of eels, with the link to a previous question and answer: 多亏了充满鳗鱼的气垫船,以及上一个问题和答案的链接:

CardLayout changing panel from another class 另一个类的CardLayout更改面板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM