privateJFramefrmQuestion;privatestaticJTextFieldtextField;privateStringname;JLabellblWelcome=newJLabel("Welcome: "+name);/** * Launch the application. */publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{Corewindow=newCore();window.frmQuestion.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/** * Create the application. */publicCore(){initialize();}/** * Initialize the contents of the frame. */privatevoidinitialize(){frmQuestion=newJFrame();frmQuestion.setTitle("Question");frmQuestion.setResizable(false);frmQuestion.setBounds(100,100,679,107);frmQuestion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);textField=newJTextField();textField.addInputMethodListener(newInputMethodListener(){publicvoidcaretPositionChanged(InputMethodEventarg0){}publicvoidinputMethodTextChanged(InputMethodEventarg0){}});textField.setColumns(10);JLabellblWhatIsYour=newJLabel("What is Your Name?");lblWhatIsYour.setFont(newFont("Arial Black",Font.BOLD,17));JButtonbtnNext=newJButton("Next");btnNext.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventarg0){name=textField.getText();JOptionPane.showMessageDialog(null,"Welcome"+name+"wehavebeenwaitingforyou...");}});GroupLayoutgroupLayout=newGroupLayout(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);}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 {
}