1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

[Solved] ? About making bold text in java

Discussion in 'Software Development' started by ustacp, Aug 31, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. ustacp

    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();
    
    	}
    
    }
    
     
  2. Chicon

    Chicon

    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);
     
  3. dilip_maurya

    dilip_maurya

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

    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
     
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 733,556 other people just like you!

Loading...
Similar Threads - [Solved] making bold
  1. MarcoPotatoe
    Replies:
    1
    Views:
    722
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/268792

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice