如何将两个窗口组合成一个窗口?

时间:2019-04-22 12:32:35

标签: java swing layout-manager

我需要将带有选项卡式窗口的窗口“第一面板,第二面板,第三面板,第四面板”插入到名为“动画”的窗口中。 我应该怎么做才能使它最终看起来像:一个窗口,其中包含一个带有四个选项卡的动画框,一个文本框和一个用户输入框?

名为“ Main”的头等舱:

import java.awt.*;
import javax.swing.*;

public class Main {
    JFrame frame = new JFrame("Demo");
    JPanel panel = new JPanel();
    JLabel square1 = new JLabel("Animation");
    JLabel square2 = new JLabel("Text");
    JTextField square3 = new JTextField("User Input");

    public Main() {
        panel.setLayout(new GridLayout(2,2,3,3));
        panel.add(square1);
        panel.add(square2);
        panel.add(square3); 
        frame.add(panel);

        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setSize(600,400);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Tabbed tp = new Tabbed();       
        tp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        tp.setSize(600,400);
        tp.setVisible(true);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Main();         
            }
        });
    }
}

'第二个类,称为“ Tabbed”:'

import javax.swing.*;

public class Tabbed extends JFrame{

    private static final long serialVersionUID = 1L;

    JPanel firstPanel = new JPanel();
    JPanel secondPanel = new JPanel();
    JPanel thirdPanel = new JPanel();
    JPanel fourPanel = new JPanel();

    JLabel firstLabel = new JLabel("First!");
    JLabel secondLabel = new JLabel("Second!");
    JLabel thirdLabel = new JLabel("Third!");
    JLabel fourLabel = new JLabel("Fourth!");

    JTabbedPane tabbedPane = new JTabbedPane();

    public Tabbed(){
        firstPanel.add(firstLabel);
        secondPanel.add(secondLabel);
        thirdPanel.add(thirdLabel);
        fourPanel.add(fourLabel);

        tabbedPane.add("First panel",firstPanel);
        tabbedPane.add("Second panel",secondPanel);
        tabbedPane.add("Third panel",thirdPanel);
        tabbedPane.add("Fourth panel",fourPanel);

        add(tabbedPane);
    }
}

这是我要结合两个窗口的方式:

enter image description here

0 个答案:

没有答案