import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.Arrays; public class Main { private JFrame frame; private JPanel panel; private JLabel outputLabel; public Main(){ prepareGUI(); } public static void main(String[] args){ Main program = new Main(); program.showTextField(); } // Frame design private void prepareGUI(){ frame = new JFrame("45284 Examples"); frame.setSize(200, 150); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); outputLabel = new JLabel("", JLabel.CENTER); panel = new JPanel(); panel.setLayout(new FlowLayout()); frame.add(panel); frame.add(outputLabel); frame.setVisible(true); } private void showTextField(){ JLabel label= new JLabel("Enter value: ", JLabel.RIGHT); final JTextField text = new JTextField(6); JButton button = new JButton("Value"); // Action button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Get method String input = text.getText(); //String.split String[] inputArray = input.split(" "); //Nice output String output = Arrays.toString(inputArray); //Set method outputLabel.setText(output); } }); panel.add(label); panel.add(text); panel.add(button); frame.setVisible(true); }}
Comments