Results 1 to 2 of 2
  1. #1
    maskanio is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Java program freezing while using graphics?

    Heres my code. Go ahead try to run it. Its supposed to just display a string in a program, but instead it freezes when you try to run.
    Java Code:
    package javagame;
    import javax.swing.JFrame;
    import java.awt.Graphics;
    public class JavaGame extends JFrame {
    public JavaGame(){
    setTitle("Java Game");
    setSize(500, 500);
     public void paint(Graphics g){
         g.drawString("Hello World!", 75, 75);
        public static void main(String[] args) {
       new JavaGame();
    Oh and this isn't homework, I'm doing this for fun. Passed Java class already :)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Java program freezing while using graphics?

    You are overriding paint in the JFrame so the super class implementation is essentially ignored. You should put this as the first statement in your paint method.
    Java Code:
    Also, for future reference. Don't extend JFrame and don't draw directly in the JFrame. Check out the tutorials in my signature for tutorials on this and lots more.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Simple Graphics program not working.
    By forms in forum New To Java
    Replies: 7
    Last Post: 03-11-2012, 03:44 PM
  2. Extracting program, custom graphics goes away..
    By AndroidAppNewbie in forum New To Java
    Replies: 26
    Last Post: 03-08-2011, 07:25 PM
  3. Program Freezing While Reading Input
    By airowe in forum New To Java
    Replies: 15
    Last Post: 01-11-2011, 03:38 AM
  4. Graphics program
    By ccie007 in forum New To Java
    Replies: 6
    Last Post: 10-27-2010, 08:08 PM
  5. why does this code keep freezing?
    By berkeley in forum New To Java
    Replies: 4
    Last Post: 06-03-2010, 04:41 PM

Posting Permissions

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