Results 1 to 3 of 3
  1. #1
    Timzy921 is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Does anyone know why this happens?

    * Fixed *

    Hey guys on my second day on Java, and I'm using the JFrame and I guess I'm having some sorta problem.



    Heres the source
    [Java] JFrame Problem - Pastebin.com


    Any help would be nice

    import javax.swing.*;
    import java.awt.*;

    public class dashboard extends JFrame {

    public static void main(String[] agrs)
    {
    new dashboard();
    }

    public dashboard()
    {
    this.setSize(500,500);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    this.setTitle("OEMGE APP");
    this.setLocationRelativeTo(null);
    this.setResizable(false);

    JPanel p = new JPanel(new FlowLayout());
    JTextField welcomeMSG = new JTextField("Hello There");
    JButton randomButton = new JButton("Click Me :D");
    p.add(welcomeMSG);
    p.add(randomButton);
    this.add(p);
    }

    }

    Had to change it to

    import javax.swing.*;
    import java.awt.*;

    public class dashboard extends JFrame {

    public static void main(String[] agrs)
    {
    new dashboard().setVisible(true);
    }

    public dashboard()
    {
    this.setSize(500,500);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    this.setTitle("OEMGE APP");
    this.setLocationRelativeTo(null);
    this.setResizable(false);

    JPanel p = new JPanel(new FlowLayout());
    JTextField welcomeMSG = new JTextField("Hello There");
    JButton randomButton = new JButton("Click Me :D");
    p.add(welcomeMSG);
    p.add(randomButton);
    this.add(p);
    }

    }
    Last edited by Timzy921; 03-27-2012 at 03:54 AM.

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

    Default Re: Does anyone know why this happens?

    Please post your code in the forum, not in a link. Since you're asking for free help, is it asking too much for you to try to make it easy for others to help you? Also, write out your question in the forum itself. Not everyone has the same band width as you, and not all understand spoken English as well as written English.

    But regarding your problem, look at where you're calling setVisible(true) on your JFrame vs. where you are adding components. Try playing with order that some.

  3. #3
    Timzy921 is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: Does anyone know why this happens?

    Sorry to anyone who wanted to help and came as an inconvenience. Though I did figure the problem out so thanks for the help ^_^

Tags for this Thread

Posting Permissions

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