Reply
Thu 29 Mar, 2012 03:19 am
I following code:
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.*;
public class ShowFlowLayout extends JFrame {
public ShowFlowLayout() {
// Set FlowLayout, aligned left with horizontal gap 10
// and vertical gap 20 between components
setLayout(new FlowLayout(FlowLayout.LEFT, 10, 20));
// alustetaan swing olio pnlNorth
JPanel pnlNorth = new JPanel();
// Painike laitettavaksi paneeliin
JButton btnNorth = new JButton("North");
// Add labels and text fields to the frame
add(new JLabel("First Name"));
add(new JTextField(8));
add(new JLabel("MI"));
add(new JTextField(1));
add(new JLabel("Last Name"));
add(new JTextField(8));
add(new JButton("lähetä"));
pnlNorth.add(btnNorth);
add(pnlNorth);
}
/** Main method */
public static void main(String[] args) {
ShowFlowLayout frame = new ShowFlowLayout();
frame.setTitle("ShowFlowLayout");
frame.setSize(200, 200);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EX…
frame.setVisible(true);
}
}
How do I implement program so that it uses actionListener - class and actionPerformed - method in collecting data that user has written into textfield First Name, textfield MI and textfield Lastname. It collects data from user, when user presses JButton lähetä.