Discussion Locked

Adding Fonts and Colour in a .java Game

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can't seem to incorporate new Fonts() and Colour into my Game...Any Suggestions?:import java.io.*;
import java.util.Random;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JOptionPane;
import java.io.PrintStream;
import java.awt.*;
import javax.swing.*;

public class Guesses extends JFrame
{
public static void main(String[] args) throws IOException
{

Random generator = new Random();//generator represents random number
int number;
number = generator.nextInt(100) + 1;

int guess=number;
String myNumber;
String DataEntry;
String challenge="Try to guess the number I'm thinking of!";
String high="too high - guess again:";
String low="too low - guess again:";
String correct1="Finally you got it out! You only took ";
String correct2=" tries to get the correct number ";

JOptionPane.showMessageDialog( null, challenge,"Today's Challenge: ",
JOptionPane.INFORMATION_MESSAGE );

int myInt;
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
boolean found=false;

for(int i=1;(!found);i++)
{

DataEntry = JOptionPane.showInputDialog( "Type your number here:" );
myInt=Integer.parseInt(DataEntry);

if (guessmyInt)
JOptionPane.showMessageDialog(null, low,"Today's Challenge: ",
JOptionPane.INFORMATION_MESSAGE);

else {
JOptionPane.showMessageDialog(null, correct1+i+correct2+number,
"Today's Challenge: ",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}
}

2 replies

by g...

JOptionPane has his standard for font and colour. I don't recall how to change this neither if it's possible. I think you will have to design your own pane. But anyway, if it's possible, there's nothing in your code to call those. Eventually check the API at java.sun.com.

In my opinion the easyest way to do so is to use the Visual Editor (VE) from the Eclipse project. kind of drag and drop to have things as you want them and just coding the program itself.
Very good and totally free...

by g...

Thinkng about it I recall a setFont that you can use on a JOptionPane but just to set a font name that must be on the system but no color

This discussion is closed to new replies.