Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java not drawing my string

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java not drawing my string

    Hey guys,

    I'm learning some Java and I got stuck on a problem.

    Here's my Main.java :

    import java.awt.Graphics;
    import java.awt.Graphics2D;

    import javax.swing.JPanel;

    public class GameFrame extends JPanel {

    public GameFrame() {
    setFocusable(true);
    }

    public void Paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.drawString("Hello world", 150, 200);
    }
    }

    And here's my GameFrame.java :

    import javax.swing.JFrame;


    public class Main {
    public static void main(String[] args) {
    JFrame frame = new JFrame("Game");
    frame.setSize(854, 480);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.add(new GameFrame());
    frame.setVisible(true);
    frame.setResizable(false);
    }

    }

    It creates the JFrame but it's not drawing my text.
    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java not drawing my string

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Check the spelling, java is case sensitive
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Drawing Image in Java
    By Shania_01 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2013, 12:10 PM
  2. Drawing a string without use of Main(String[] args)
    By JakkyD in forum AWT / Java Swing
    Replies: 4
    Last Post: December 17th, 2012, 11:14 PM
  3. [SOLVED] Drawing lines using angles in Java HELP
    By shadysback in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 8th, 2012, 02:10 PM
  4. Incremental image drawing in Java
    By ea25 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 14th, 2011, 07:58 AM
  5. Strange problem with drawing string
    By Asido in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 26th, 2010, 03:38 PM