Answer to Question #45284 in Java | JSP | JSF for sharryjean

Question #45284
how to call getters and setters method if they are set using swing and if the user's entry will store on an array type and the user is allowed to enter data
1
Expert's answer
2014-08-28T05:42:58-0400
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);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS