Web Development

General discussion


Adding Fonts and Colour in a .java Game

By hamant5 ·
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: ",

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:" );

if (guess<myInt)
JOptionPane.showMessageDialog(null, high,"Today's Challenge: ",

else if
JOptionPane.showMessageDialog(null, low,"Today's Challenge: ",

else {
JOptionPane.showMessageDialog(null, correct1+i+correct2+number,
"Today's Challenge: ",

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by G... In reply to Adding Fonts and Colour i ...

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...

Collapse -

by G... In reply to

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

Related Discussions

Related Forums