• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two questions

 
Koert Kopbeen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey

I have three questions:

1) How do I change the font of Strings in Java?

2) How do you create a countdown timer (let's say you coded a game and it then says: "The program will exit in 10 seconds if you dont enter a choice") in Java?

Thanks
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Koert Kopbeen:
Hey

I have three questions:




Hey

I have three answers.

1. How do I change the font of Strings in Java?


Take a look at Java documentation forFontclass
Here is the sample code.

2. How do you create a countdown timer ?

Well, there are several ways to do it.
The simplest one I found is to create a seperate thread which will keep checking for the input every second and will take action if no input was supplied in specified time.
[ November 04, 2005: Message edited by: Deep Narsay ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4021
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 more questions or answers:

1. In what way do you (Koert Kopbeen) mean to change the font? The class only works if you are using Swing or something similar. If you're talking in an output file or a system out, there is no such way. Alternatively, if it is HTML, you just insert HTML codes.

2. You don't need to create a second thread if you don't mind the application pausing while waiting for input (so if you want to do other things while waiting 10 seconds, you need a second thread, but it doesn't sound like you do). In this case you can just call Thread.sleep() every second (or half second if you'd prefer) for 10 seconds and check keyboard input each iteration.

3. Deep Narsay, how is that 3 answers? ><
[ November 04, 2005: Message edited by: Scott Selikoff ]
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Selikoff:
3. Deep Narsay, how is that 3 answers? ><

[ November 04, 2005: Message edited by: Scott Selikoff ]


Koert said "I have three questions"

I replied "I have three answers"

Now, as soon as he asks third question, I will shoot the answer.

 
Koert Kopbeen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey

Ja sorry I made a mistake - just two questions.

I am referring to normal Strings in Java. I have seen that it is possible to change the font (I use Ready to Program - the normal font of the code is Courier New: I believe that is the regular font across platforms) in Buttons etc, but I want a certain part of the String to stand out. How do I do that - let's say change a part of the program to Times New Roman or something.

The timer: is there not maybe a method in Java to do it? I would like to display the counted time in the program. How do I do that?

OK, so maybe I do have a third question. Again about Strings: how do I make a certain part of text flicker?

And a fourth one: Whenever I use PrintWriter of the java.io class, it erases the contents of the .txt file completely. No matter what I type in there, it erases it. Any ideas? Anyone had this same problem?

Cool people!

Koert

PS: Mag dinge vir julle net goedgaan - anders as met myself wannneer dit kom by Rekenaarstudie HG!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic