您应审查Swaing AP。 案文领域将是JText 现场。 http://docs.oracle.com/javase/6/docs/api/“rel=“nofollow”http://docs.oracle.com/javase/6/docs/api/。 http://docs/api/javax/swing/JText Field.html
这里有些非常简便的法典是你想要的(我无视布局,i18n,以及其他各种改进):
JTextField usernameTextField = new JTextField("Username:");
JButton saveButton = new JButton("Save");
saveButton.addActionListener(new ActionListener())
{
public void actionPerformed(ActionEvent e)
{
String username = usernameTextField.getText();
//Put validation code here if you want
//Then put your SQL insert statement code here
}
});
//Generally you will be adding them to a JPanel, but can be a JFrame for simple cases
panel.add(usernameTextField);
panel.add(saveButton);
...