Results 1 to 6 of 6
  1. #1
    vividcooper is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Question positining of word

    Hi i was just wondering if i can specify in my code to have a title being displayed in the middle of the screen.

    instead of using a lot of white lines. example:
    System.out.println(" Welcome");

    can I write a code so that the Welcome letter be displayed in the middle of the screen?
    thank you!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Is this a Swing or AWT GUI application, or are we talking a simple console app (as suggested by the println statement above)?

  3. #3
    vividcooper is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    no its only a println statement

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by vividcooper View Post
    no its only a println statement
    Then I think that your best bet is to call a bunch of println statements, perhaps using a for loop, and also padding your String with spaces, again perhaps using a for loop.

  5. #5
    bdtagar is offline Member
    Join Date
    Jun 2009
    Posts
    11
    Rep Power
    0

    Default

    Hi,
    Use this code:
    System.out.println("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t Welcome");

    AND bye...

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    or...
    Java Code:
    import java.awt.Font;
    import javax.swing.*;
    
    public class WelcomeGui {
      private static final float FONT_SIZE = 200;
      private static final String WELCOME_TEXT = "Welcome!";
    
      private static void createAndShowUI() {
        JLabel welcomeLabel = new JLabel(WELCOME_TEXT, SwingConstants.CENTER);
        welcomeLabel.setFont(welcomeLabel.getFont().deriveFont(Font.BOLD, FONT_SIZE));
        welcomeLabel.setBorder(BorderFactory.createEmptyBorder(40, 40, 40, 40));
        
        JFrame frame = new JFrame("WelcomeGui");
        frame.getContentPane().add(welcomeLabel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
            createAndShowUI();
          }
        });
      }
    }

Similar Threads

  1. Word
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 04:25 AM
  2. Word Jumbler
    By wethekings in forum New To Java
    Replies: 7
    Last Post: 02-20-2009, 05:57 AM
  3. Word Frequency
    By capu in forum Advanced Java
    Replies: 2
    Last Post: 10-09-2008, 03:03 PM
  4. Word OLE
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 03:33 PM
  5. Word Scramble
    By lk9865 in forum New To Java
    Replies: 5
    Last Post: 11-17-2007, 03:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •