JTextField에 actionListener를 추가하는 데 문제가 있습니다. 사용자가 입력 한 텍스트를 문자열로 가져와서 작업 할 수 있어야합니다.GridBagLayout의 JTextField ActionListener
누구나 내가 잘못하고있는 일이나 내가 어떻게해야 하는지를 알 수 있습니까?
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
JFrame frame = new JFrame("Value Bet");
frame.setVisible(true);
frame.setSize(500,300);
GridBagLayout layout = new GridBagLayout();
frame.setLayout(layout);
GridBagConstraints c = new GridBagConstraints();
JLabel label;
JTextField tf;
if (shouldFill) {
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
}
if (shouldWeightX) {
c.weightx = 0.5;
}
...
tf = new JTextField();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 2;
frame.add(tf, c);
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String chance1 = tf.getText();
}
});
...
문서 수신기를 사용하면 사용자 입력을 변수에도 저장할 수 있습니까? 그리고 어떻게? –