Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java problem

  • 23-11-2004 12:08pm
    #1
    Registered Users, Registered Users 2 Posts: 937 ✭✭✭


    Im havin trouble makin a basic window with java...see code below..any help/suggestions greatly appreciated

    main.java
    class ShowAFrame 
    {
       
        public static void main(String args[])
        {
          new SimpleFrame();
        }
        
    }
    

    SimpleFrame.java
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    
    
    class SimpleFrame extends JFrame 
    
    {
        public SimpleFrame()
        {
            setTitle("Don't click the button!");
            setLayout(new FlowLayout());
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(new JButton("Panic"));
            setSize(300,100);
            setVisible(true);
        }
        
    }
    

    there all in a package (using netbeans 4)


Comments

  • Registered Users, Registered Users 2 Posts: 2,714 ✭✭✭Darwin


    In main add:

    SimpleFrame myFrame = new SimpleFrame();
    myFrame.show();

    I haven't bothered to run your code, but I presume your code compiles and the Frame is not showing.


  • Registered Users, Registered Users 2 Posts: 261 ✭✭HaVoC


    put:
    SimpleFrame f = new SimpleFrame();
    f.pack();
    f.setVisible(true);

    in your main method you have to run pack() and setVisible(true) for the window to actually appear.


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    nah, they dont seem to help very much, i still get the errors
    errors:
    java.lang.NoClassDefFoundError: ShowAFrame/main
    Exception in thread "main" 
    Java Result: 1
    


  • Registered Users, Registered Users 2 Posts: 17,727 ✭✭✭✭Sherifu


    Shouldn't main.java be called ShowAFrame.java?

    RKM.


  • Registered Users, Registered Users 2 Posts: 2,714 ✭✭✭Darwin


    put:
    SimpleFrame f = new SimpleFrame();
    f.pack();
    f.setVisible(true);

    in your main method you have to run pack() and setVisible(true) for the window to actually appear

    setVisible has been set to true in the constructor already.

    Shouldn't main.java be called ShowAFrame.java?

    Of course..didn't spot this.


  • Advertisement
  • Closed Accounts Posts: 92 ✭✭tempest


    getContentPane().add(new JButton("Panic"));


  • Registered Users, Registered Users 2 Posts: 2,714 ✭✭✭Darwin




  • Registered Users, Registered Users 2 Posts: 261 ✭✭HaVoC


    Darwin wrote:
    setVisible has been set to true in the constructor already.




    Of course. didn’t spot this.

    oh right didn’t spot that just .pack() so in the constructor before .setVisible(true);
    .show() has been deprecated by .setVisible(true);


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    cheers lads


  • Registered Users, Registered Users 2 Posts: 27,465 ✭✭✭✭GreeBo


    rmulryan wrote:
    Shouldn't main.java be called ShowAFrame.java?

    RKM.
    yep
    :rolleyes:


  • Advertisement
  • Closed Accounts Posts: 18 moonser


    does anyone know where i can download the complete java api file so i dont have to use the book please.


  • Registered Users, Registered Users 2 Posts: 27,465 ✭✭✭✭GreeBo


    moonser wrote:
    does anyone know where i can download the complete java api file so i dont have to use the book please.
    1.4.2 JavaDoc


  • Closed Accounts Posts: 18 moonser


    cheers man


  • Registered Users, Registered Users 2 Posts: 27,465 ✭✭✭✭GreeBo


    np.


Advertisement