Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Two questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Two questions" Watch "Two questions" New topic
Author

Two questions

Koert Kopbeen
Greenhorn

Joined: Oct 30, 2005
Posts: 6
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

Joined: Sep 05, 2001
Posts: 139
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 ]

SCJP2
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

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 ]

My Blog: Down Home Country Coding with Scott Selikoff
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
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

Joined: Oct 30, 2005
Posts: 6
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two questions
 
Similar Threads
Books Approach
Awesome books but
FREE Certification Beta: Sun Certified Specialist Netbeans IDE
Problems running java
Help me