Oi!
Estou desenvolvendo um jogo simples em Java. Mas, não estou consiguindo ver os textos no Frame, sendo que, eu o adcionei.
Quero saber de vocês também, se estou indo no caminho certo.
Obrigado!
//TicTacToe.java
//TicTacToe - Jogo da velha
import javax.swing.JOptionPane;
import java.util.Scanner;
public class TicTacToe extends Play {
private String arrayEnter[];
String namePlayerOne;
String namePlayerTwo;
//create Scanner for get info
Scanner input = new Scanner(System.in);
//construct start
public TicTacToe()
{
JOptionPane.showMessageDialog(null, "Welcome to game!");
namePlayerOne = JOptionPane.showInputDialog("Write your name: ");
namePlayerTwo = JOptionPane.showInputDialog("Now, write the name of other player: ");
displayMessageUser();
}
//add name of user
public void addUser(String nameOne, String nameTwo)
{
namePlayerOne = nameOne;
namePlayerTwo = nameTwo;
}
//return name of user
public String getUser()
{
return namePlayerOne;
}
//method for display message of welcome for user
public void displayMessageUser()
{
//options for user
String valueEnter = JOptionPane.showInputDialog(null,"Write Play for play\nOr Exit for exit.");
if (valueEnter.equalsIgnoreCase("Play"))
{
Play playGame = new Play();
playGame.Play();
} else if (valueEnter.equalsIgnoreCase("Exit")) {
exitOptions();
}
}
//Message of output; case the user choose the option exit
public void exitOptions()
{
JOptionPane.showMessageDialog(null, "Thanks you!", "End program",JOptionPane.INFORMATION_MESSAGE);
}
}
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.FlowLayout;
public class Play extends JFrame {
private JTextField welcomeUser;
private JTextField help;
private int start[][]; //start array bidimensional
JFrame labelFrame = new JFrame(); //create LabelFrame
public void Play()
{
setLayout(new FlowLayout());
welcomeUser = new JTextField("Welcome to Game!");
add(welcomeUser);
help = new JTextField("Get help!");
add(help);
}
}
import javax.swing.JFrame;
public class Principal {
public static void main(String args[])
{
TicTacToe tic = new TicTacToe();
tic.setTitle("Game simple on Java!");
tic.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tic.setSize(500, 200);
tic.setVisible(true);
}
}