Hello dear forum members. For some reason, the getText () method does not work. Please tell me: what is the problem. Something even goes nothing.

public class ClickListener implements ActionListener{ Integer ids; Socket s = new Socket(); ClientRegistrator cm = new ClientRegistrator(); VisualFrame vf = new VisualFrame(); String line1 = null; String line2 = null; public void variable(Socket socket, Integer id) { ids = id; s = socket; } @Override public void actionPerformed(ActionEvent arg0) { try { DataOutputStream dout = new DataOutputStream(new BufferedOutputStream(s.getOutputStream())); System.out.println("OutStream on start"); System.out.println(line1); System.out.println(line2); Thread.sleep(100); line1 = vf.JTA1.getText(); line2 = vf.JTA2.getText(); System.out.println(line1); System.out.println(line2); dout.writeUTF(line1); dout.writeUTF(line2); dout.flush(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public class VisualFrame { JFrame jf = new JFrame(); JTextArea JTA3 = new JTextArea(30, 100); JTextArea JTA2 = new JTextArea(); JTextArea JTA1 = new JTextArea(12, 1); JScrollBar JSB = new JScrollBar(); public void visual() { jf.setDefaultLookAndFeelDecorated(true); jf.setLayout(null); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(1500, 1500); jf.setVisible(true); ClientRegistrator cm = new ClientRegistrator(); ModifyFrame mf = new ModifyFrame(); JTA1.setVisible(true); JTA1.setBounds(515, 0, 100, 30); JTA1.setWrapStyleWord(true); JTA1.setLineWrap(true); JTA1.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "", TitledBorder.RIGHT, TitledBorder.BOTTOM, null, Color.blue)); JTA2.setBounds(515, 35, 100, 100); JTA2.setVisible(true); JTA2.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "", TitledBorder.RIGHT, TitledBorder.BOTTOM, null, Color.blue)); JTA3.setBounds(625, 0, 500, 500); JTA3.setVisible(true); JTA3.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "", TitledBorder.RIGHT, TitledBorder.BOTTOM, null, Color.blue)); JTA3.setBackground(Color.GRAY); JTA2.setEditable(true); JTA3.setEditable(true); JTA2.setWrapStyleWord(true); JTA2.setLineWrap(true); JTA3.setWrapStyleWord(true); JTA3.setLineWrap(true); jf.add(JTA3); jf.add(JTA2); jf.add(JTA1); jf.add(cm.JCP); jf.repaint(); cm.worker1(); } 
  • Java doing month. Please do not judge strictly) - lemuur
  • one
    And you also ask questions only a month? There is no getText() method in your bed sheet at all! And what does "not working" mean? Home lying on the couch and the box is looking? - user194374
  • Corrected. It does not work - it means: it does not fulfill its function. - lemuur
  • And what does "not fulfill" mean? What is it expressed in? - user194374
  • one
    And why at you VisualFrame in Listener 'e? That seems to be the problem. - user194374

2 answers 2

And why do you have a VisualFrame created in the Listener? That seems to be the problem. From @kff Thus, the problem was solved. Thank you very much for the answer.

    You should better consider the architecture of the application and rename the variables. Try to give the variables meaningful names so that the name of the variable would understand why it is needed and where it is used, it will improve the readability of the code. As an example, there is a button that sends the package to the server, call it can be something like this: sendPacketButton.