Show textfield or textarea java

Asked

Viewed 1,807 times

5

I can’t show words in textfield (or textarea) in my code, several hours in this and I still can’t.

I got a link to the code.
The most important lines are these, but if you want to test the whole code, it’s easier to help, I think.

import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

private JTextArea textArea;
int player;
private DataInputStream input;
private JTextField id;


JPanel middlePanel=new JPanel();     
JTextArea display=new JTextArea(12,12);
display.setEditable(true); //false
JScrollPane scroll=new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
middlePanel.add(scroll);
window.add(middlePanel, BorderLayout.EAST);
display.setText("Jogador(Player) 1");


middlePanel.setBorder(new TitledBorder(new EtchedBorder(),"Informações                            Chat"));        
JTextArea display2=new JTextArea(12,12);
display2.setEditable(true); 
JScrollPane scroll2=new JScrollPane(display2);
scroll2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
middlePanel.add(scroll2);
window.add(middlePanel, BorderLayout.EAST);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);    
window.resize(700,500);

I have doubt mainly in this part of code:

public void run()
{
    // Primeiro a jogar jogador 1, segundo 2
    try 
    {          
        player=input.readChar();
        textArea.setText("You are player \""+ player + "\"");
        myTurn=(player == '1' ? true : false);
    } 

Briefly: The text in quotes " " is not shown for the textarea or textField (only blank squares with vertical offset bars appear). That’s why I’m so screwed up, I have to deliver the paper in a few days.

The only text that is shown is display.setText("Player(Player) 1");

Otherwise Jtextarea is all blank. I can’t identify the problem.

  • This question is just over two years old, the code is incomplete and the link is to another question already deleted from the same author who had only a few more things that would not help answer the question. The missing parts of the code cannot be filled in by anyone who wants to answer it. After all this time, it’s unlikely the AP will still be interested in her. Therefore, unfortunately this question cannot be adequately answered and it is unlikely that the author will return to correct it. Therefore, unfortunately there is no possible end to it other than closure.

1 answer

0

Try to Put in your code one more quote after the last + sign, apparently one seems to be missing , who knows solves.

textArea.setText("You are player \""+ player + ""\"");
  • Gives illegal error Character:: '. Even with System.out.println("123"). On the line above // First to play player 1, second 2. Does not show "123", nor on netbeans console output, nor in client window textarea.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.