[Solved] ? About making bold text in java

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ustacp

Thread Starter
Joined
Aug 13, 2004
Messages
292
Ok I am makeing a very simple program that the user will enter their name, address, city, state, zip code, and phone number. It will then print it to a txt file that I desgnate. It will print it for multiple users. Well, when it saves 2 or more users entrys it does not skip a line to seperate them. Now I know you can have it skip a line but I do not want it to because I am going to be adding a search into it later on and skipping a line will mess it up. I was wondering if there is a way to make the users name print out in bold letters into the text document so that I can see where each users info starts and so that it doesnt look all combinded together? Just wondering if there is any code I can include? If so can you tell me where to put it at and how to to it? Thanks.
Program is attached below:

Code:
import java.io.*;

public class address
{
	public static void main(String[] args)
	{

		String name, address, city, state, phonenumber;
		int zipcode;
		char answer;


		  System.out.println("Welcome to my program! ");
		  System.out.println();

		  PrintWriter addressoutfile = null;

            try
		    {
		        addressoutfile = new PrintWriter(new FileOutputStream("allimput.txt", true));
			}

		    catch(Exception e)
		    {
				System.out.println("Error opening the file \'allimput.txt\'");
			}

            do
		    {
				System.out.println("Please enter your name. ");
		        name = SavitchIn.readLine();
		        System.out.println();
		        System.out.println("Please enter your address. ");
		        address = SavitchIn.readLine();
		        System.out.println();
		        System.out.println("Please enter your city. ");
		        city = SavitchIn.readLine();
		        System.out.println();
		        System.out.println("Please enter your state. ");
		        state = SavitchIn.readLine();
		        System.out.println();
		        System.out.println("Please enter your zip code. ");
		        zipcode = SavitchIn.readLineInt();
		        System.out.println();
		        System.out.println("Please enter your phone number. ");
		        phonenumber = SavitchIn.readLine();
		        System.out.println();

                System.out.print("Is all of your information correct? ");
			    answer = SavitchIn.readLineNonwhiteChar();
			    System.out.println();

            }while(answer == 'n');




                System.out.println();
                System.out.println("Here is what was save on the file: \n" + name + "\n" + address + "\n" + city + "\n" + state +  "\n" + zipcode +  "\n" + phonenumber);


                addressoutfile.println(name);
                addressoutfile.println(address);
                addressoutfile.println(city);
                addressoutfile.println(state);
                addressoutfile.println(zipcode);
                addressoutfile.println(phonenumber);


                addressoutfile.close();

	}

}
 
Joined
Jul 29, 2004
Messages
6,650
Hi ustacp,

Just use a string of characters that will never be entered in a name, address, etc... as a separator :
something like this :

String header = "$*$";

and you add
addressoutfile.println(header);

before the addressoutfile.println(name);
 
Joined
Aug 28, 2004
Messages
6
You can change the font style to bold by creating a new font (import awt.font.*).
But for this font to work u should have a graphics object, which is not there in ur
case.

So instead of making the font bold, u can insert some special symbol or code
(like *** or ⌠ )before every users name. This special code will help u to distinguish
between users.Thus a statement begining with special code, is a different user.
Eg.
***XYZ USER 1
23434576
Bombay
***ABC USER 2
68970860
Delhi
***PQR USER 3
87567957
uuuuuuuuu
 

ustacp

Thread Starter
Joined
Aug 13, 2004
Messages
292
Thanks for the replies. The simplest things can be the hardest lol. I used
String header = "___________________"; which basically boxes the info in. Thanks
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top