Click the button without using GUI

1

I'm developing a system in java and would like to do it in a more organized way, then without the use of the netBeans tool to click and drag, however I am very difficult to do a simple click on the exit button of the system. How to do?

    
asked by anonymous 05.03.2015 / 21:08

1 answer

1

What is the difficulty of this?

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * @author Victor
 */
public class TelaSair {
    public static void main(String[] args) {
        EventQueue.invokeLater(TelaSair::criarTela);
    }

    private static void criarTela() {
        JFrame tela = new JFrame("Isto é uma tela");
        tela.setResizable(true);
        tela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JButton seuBotao = new JButton("Sair");
        seuBotao.setPreferredSize(new Dimension(300, 30));
        tela.add(seuBotao);
        seuBotao.addActionListener(e -> tela.dispose());
        tela.pack();
        tela.setVisible(true);
    }
}

Compile and run with Java 8.

    
05.03.2015 / 21:17