Test.java Source code

Java tutorial

Introduction

Here is the source code for Test.java

Source

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test extends JFrame {
    public static void main(String[] argv) {
        Test window = new Test();
        window.setVisible(true);

    }

    public Test() {
        this.setBounds(100, 100, 200, 100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1, true));

        this.setLayout(new FlowLayout());

        JButton exitButton = new JButton("Exit");
        panel.add(exitButton);
        this.add(panel);

        exitButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                System.exit(0);
            }
        });
    }
}