Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
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.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

public class Main {
    public static void main(String[] args) {
        JPanel gui = new JPanel(new BorderLayout());
        gui.setPreferredSize(new Dimension(400, 100));

        JDesktopPane dtp = new JDesktopPane();
        gui.add(dtp, BorderLayout.CENTER);

        JButton newFrame = new JButton("Add Frame");

        ActionListener listener = new ActionListener() {
            private int disp = 10;

            @Override
            public void actionPerformed(ActionEvent e) {
                JInternalFrame jif = new JInternalFrame();
                dtp.add(jif);
                jif.setLocation(disp, disp);
                jif.setSize(100, 100);
                disp += 10;
                jif.setVisible(true);
            }
        };
        newFrame.addActionListener(listener);

        gui.add(newFrame, BorderLayout.PAGE_START);

        JFrame f = new JFrame();
        f.add(gui);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.setLocationByPlatform(true);

        f.pack();
        f.setVisible(true);
    }
}