Jeroen Mathon - 2013-01-01

What this code does is Asking you for your name and then it will out put your name in an dialog!

File Link!

http://sourceforge.net/projects/code2gether/files/Applications/Java/Jeroen%20Mathon/What%20is%20Your%20Name/What_is_your_name.jar/download


import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Core {

private JFrame frmQuestion;
private static JTextField textField;
private String name;
JLabel lblWelcome = new JLabel("Welcome: " + name);
/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Core window = new Core();
                window.frmQuestion.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public Core() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmQuestion = new JFrame();
    frmQuestion.setTitle("Question");
    frmQuestion.setResizable(false);
    frmQuestion.setBounds(100, 100, 679, 107);
    frmQuestion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    textField = new JTextField();
    textField.addInputMethodListener(new InputMethodListener() {
        public void caretPositionChanged(InputMethodEvent arg0) {
        }
        public void inputMethodTextChanged(InputMethodEvent arg0) {

        }
    });
    textField.setColumns(10);

    JLabel lblWhatIsYour = new JLabel("What is Your Name?");
    lblWhatIsYour.setFont(new Font("Arial Black", Font.BOLD, 17));

    JButton btnNext = new JButton("Next");
    btnNext.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        name = textField.getText();
        JOptionPane.showMessageDialog(null, "Welcome " + name + " we have been waiting for you...");
                }
    });
    GroupLayout groupLayout = new GroupLayout(frmQuestion.getContentPane());
    groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(160)
                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, 337, GroupLayout.PREFERRED_SIZE)
                        .addGap(38)
                        .addComponent(btnNext))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(215)
                        .addComponent(lblWhatIsYour)))
                .addContainerGap(99, Short.MAX_VALUE))
    );
    groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.TRAILING)
            .addGroup(groupLayout.createSequentialGroup()
                .addContainerGap(379, Short.MAX_VALUE)
                .addComponent(lblWhatIsYour)
                .addGap(18)
                .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnNext))
                .addContainerGap())
    );
    frmQuestion.getContentPane().setLayout(groupLayout);
}

}