-2

I made a minesweeper game,it prints the board with println on console,but now i need to make a GUI,i need help with the method to print on a textArea or textPane,here is what i have so far

     public void mostraTela(char tabuleiro[][]){
    System.out.println("\n     Lines");
    for(int lines = 8 ; lines > 0 ; linnes--){
        System.out.print("       "+linha + " ");

        for(int coluna = 1 ; coluna < 9 ; coluna++){
            System.out.print("   "+ tabuleiro[lines][coluna]);
        }

        System.out.println();
    }

    System.out.println("\n            1   2   3   4   5   6   7   8");
    System.out.println("                      Colunas");

this method is on gui code,it is called by the Game class,i just need to make it print on a textArea

Bruno Mazzardo
  • 1,586
  • 1
  • 15
  • 27
  • Do you know anything, how these GUI components are used? – Mordechai Jun 20 '16 at 19:42
  • Describe what you have tried. What you whant say by "Print on JtextArea or JtextPane"? If is just to put the text in a JTextArea, the setText doesn't works? – pedrohreis Jun 20 '16 at 19:42
  • so far i have, a layered pane, and 2 panels,one with the buttons to start a new game or save a game,they are working,and the second pane has a JtextArea, i tried to use set.textArea,but it resets the area,and i need to add text. – Bruno Mazzardo Jun 20 '16 at 19:53
  • It looks like you're trying to shoehorn a non-GUI interface onto a GUI game, and if so, don't. Don't try printing out the UI to a JTextArea or a JTextPane, and instead use a JPanel that holds JButtons in a GridLayout. – Hovercraft Full Of Eels Jun 20 '16 at 21:04

1 Answers1

0

If you're trying to set the text to something that can't be changed then you'd want to use a JLabel.

But if what you want to do is something like having a JTextArea, have a default text set:

 jTextArea.setText("Whatever you want to be displayed in the Text Field");
Ishnark
  • 661
  • 6
  • 14