import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; public class cPanel extends JPanel { public cPanel() { setLayout(null); JTextArea textIN = new JTextArea(); textIN.setBounds(0,15,600,100); add(textIN); JTextArea textOut = new JTextArea(); textOut.setBounds(0,135,600,100); textOut.setVisible(true); add(textOut); JButton btnGJD = new JButton("CHANGE"); btnGJD.setBounds(700,75,100,100); add(btnGJD); char[] chars = {'[',']'}; String IN = textIN.getText();//////////////???????///////////// String[] tmp = IN.split(" "); btnGJD.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String tmpfinal = String.valueOf(Arrays.asList(tmp[0])).replace('[',' ').replace(']',' '); textOut.append(tmpfinal.trim().concat("ka")); } }); } - What does "not working" mean? Returns an empty string? NPE throws? - Yuriy SPb ♦
- Returns an empty array element. With no exceptions. I tried just textOut. append (IN); displays nothing. - Maxim Demyanyuk
- Maybe the matter is that the text is not in the text field? ... - Yuriy SPb ♦
- @ YuriySPb well I entered :) - Maxim Demyanyuk
- oneBut at the time of input, tmp has nothing in itself. - Yuriy SPb ♦
|
1 answer
You use an array in the click listener that is empty at the time of creation. You need to re-fill it when you click
btnGJD.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String IN = textIN.getText(); String[] tmp = IN.split(" "); String tmpfinal = String.valueOf(Arrays.asList(tmp[0])).replace('[',' ').replace(']',' '); textOut.append(tmpfinal.trim().concat("ka")); } }); - 2Lord ... Something is not right, you need to drink coffee. Thank you very much. - Maxim Demyanyuk
|