Discussion Locked

Changing Fonts & Font Color, JOptionPane

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

Can anyone help me change the Fonts & Color of my Texts..:(...?
import java.io.*;
import java.util.Random;//needed for generating random number
import java.applet.Applet;//used for display of applet windows
import java.awt.Color;//adding colour
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
import java.awt.Font;

public class Guesses extends java.applet.Applet
{
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;//from JOptionPane
String DataEntry;
String challenge="Try to guess the number I'm thinking of!";
String challenge2=challenge+Color.RED;
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, challenge2,"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);
}
}
}
}

4 replies

by martin simons

Swing components can use html in labels (which
JOptionPane also uses, so try this:

String bogus = "rest of string"

replacing the colors, faces, and sizes to what you need/want.

by melancholyj

how can i put Font Style in this code?
JOptionPane.showMessageDialog(TestMenu.this,"This is a sample of Menus where you can access all the MenuItem ","About",JOptionPane.PLAIN_MESSAGE);

This discussion is closed to new replies.