Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. JFrame showing nothing.

JFrame showing nothing.

Scheduled Pinned Locked Moved Java
javagraphics
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chdboy
    wrote on last edited by
    #1

    I'm not able to see content on JFrame ,when JFrame shows up.

    import java.awt.*;

    import javax.swing.*;
    import java.awt.event.*;
    public class GraphicUse extends JPanel
    {
    public void PaintComponent(Graphics gr)
    {
    super.paintComponents(gr);
    this.setBackground(Color.BLUE);
    gr.setColor(Color.WHITE);
    gr.fillRect(50, 50, 100, 100);
    gr.setColor(new Color(139,38,190));
    gr.fillRect(50, 70, 100, 100);
    gr.setColor(Color.RED);
    gr.drawString("This is a new String", 50, 90);
    }

    public static void main(String\[\] args) 
    {
    }
    

    }

    And displaying it in another class which extends Frame

    JFrame newframe = new JFrame("Color Frame");
    newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GraphicUse gu = new GraphicUse();
    newframe.add(gu);
    newframe.setSize(250,300);
    newframe.setVisible(true);

    L S 2 Replies Last reply
    0
    • C chdboy

      I'm not able to see content on JFrame ,when JFrame shows up.

      import java.awt.*;

      import javax.swing.*;
      import java.awt.event.*;
      public class GraphicUse extends JPanel
      {
      public void PaintComponent(Graphics gr)
      {
      super.paintComponents(gr);
      this.setBackground(Color.BLUE);
      gr.setColor(Color.WHITE);
      gr.fillRect(50, 50, 100, 100);
      gr.setColor(new Color(139,38,190));
      gr.fillRect(50, 70, 100, 100);
      gr.setColor(Color.RED);
      gr.drawString("This is a new String", 50, 90);
      }

      public static void main(String\[\] args) 
      {
      }
      

      }

      And displaying it in another class which extends Frame

      JFrame newframe = new JFrame("Color Frame");
      newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      GraphicUse gu = new GraphicUse();
      newframe.add(gu);
      newframe.setSize(250,300);
      newframe.setVisible(true);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Why does your main method not do anything?

      Veni, vidi, abiit domum

      C 1 Reply Last reply
      0
      • L Lost User

        Why does your main method not do anything?

        Veni, vidi, abiit domum

        C Offline
        C Offline
        chdboy
        wrote on last edited by
        #3

        I'm calling this class from another class so it is using that main class main method.

        L 1 Reply Last reply
        0
        • C chdboy

          I'm calling this class from another class so it is using that main class main method.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well you need to provide some more detail about your problem.

          Veni, vidi, abiit domum

          C 1 Reply Last reply
          0
          • L Lost User

            Well you need to provide some more detail about your problem.

            Veni, vidi, abiit domum

            C Offline
            C Offline
            chdboy
            wrote on last edited by
            #5

            what other details you need?

            L 1 Reply Last reply
            0
            • C chdboy

              what other details you need?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              No idea; but you need to provide enough to help people to understand the problem. Remember, we have never seen your code before so we cannot guess what each part is supposed to do or how it fits together. Having a blank main method in the code you showed above just serves to confuse.

              Veni, vidi, abiit domum

              1 Reply Last reply
              0
              • C chdboy

                I'm not able to see content on JFrame ,when JFrame shows up.

                import java.awt.*;

                import javax.swing.*;
                import java.awt.event.*;
                public class GraphicUse extends JPanel
                {
                public void PaintComponent(Graphics gr)
                {
                super.paintComponents(gr);
                this.setBackground(Color.BLUE);
                gr.setColor(Color.WHITE);
                gr.fillRect(50, 50, 100, 100);
                gr.setColor(new Color(139,38,190));
                gr.fillRect(50, 70, 100, 100);
                gr.setColor(Color.RED);
                gr.drawString("This is a new String", 50, 90);
                }

                public static void main(String\[\] args) 
                {
                }
                

                }

                And displaying it in another class which extends Frame

                JFrame newframe = new JFrame("Color Frame");
                newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                GraphicUse gu = new GraphicUse();
                newframe.add(gu);
                newframe.setSize(250,300);
                newframe.setVisible(true);

                S Offline
                S Offline
                suvi from mumbai
                wrote on last edited by
                #7

                Your frame is covered by a gray frame thats why paint method do not show anything.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups