I am a newbie in Java, and I want to create the first step in a big system. I was trying to use Eclipse WindowsBuilder for this task, but I got a lot of code I don't understand, and furthermore, I don't know how to proceed...
What I want to do is simple. When I run my program, I want a small window (frame?) to come up with a label "user name" and a text field next to it, below I want another label "password" with a password field next to it. Below that, I want a button "submit", that when pressed, makes this window/frame close, and opens a new window/frame, bigger, in which I will put all sorts of things. This is my code, it creates the first window, I don't know how to make it do what I want when I press the button. Additionally, I am not sure how to create a new class for the new frame, without a main method, will it work ?
Thank you for any sort of help and guidance you can provide (if there is a nicer way or writing it without windowsbuilder - I am up for it).
package HR;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JFormattedTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class SignIn extends JFrame {
private JPanel contentPane;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SignIn frame = new SignIn();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public SignIn() {
setTitle("SYSTEM");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 308, 179);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FormLayout(new ColumnSpec[] {
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"),},
new RowSpec[] {
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,}));
JLabel lblNewLabel = new JLabel("User Name");
contentPane.add(lblNewLabel, "4, 4, right, default");
final JFormattedTextField username = new JFormattedTextField();
contentPane.add(username, "6, 4, 3, 1, fill, default");
JLabel lblNewLabel_1 = new JLabel("Password");
contentPane.add(lblNewLabel_1, "4, 6, right, default");
passwordField = new JPasswordField();
contentPane.add(passwordField, "6, 6, 3, 1, fill, default");
JButton btnSignIn = new JButton("Sign In");
btnSignIn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
username.setText("Me");
}
});
contentPane.add(btnSignIn, "6, 8");
}
}