1

I am about to start learning coding the GUI. Now I know that its best if you hand code it for the first time to get a grip on the concepts.

My question is this: Do I need to disable the GUI buidler in Netbeans to do this? Looked up the Netbeans Forum but could not find a clear answer. It seems most programmers still prefer the hand coding option.

Thanks for your attention

1
  • +1 for making an effort to understand the process! Commented Aug 1, 2012 at 10:14

2 Answers 2

2

No, you don't have to disable anything. You can just start writing Swing code right away.

Try it out yourself by pasting the source for the HelloWorldSwing program and run it. Here's an abbreviated version:

import javax.swing.*;        

public class HelloWorldSwing {

    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }


    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Swing can be started without anything extra heres an example.

import javax.swing.JFrame;
import javax.swing.JLabel;


public class HelloWorldFrame extends JFrame {

    //Programs entry point
    public static void main(String args[]) {
        new HelloWorldFrame();
    }

    //Class Constructor to create components
    HelloWorldFrame() {
        JLabel jlbHelloWorld = new JLabel("Hello World");
        add(jlbHelloWorld); //Add the label to the frame
        this.setSize(100, 100); //set the frame size
        setVisible(true); //Show the frame
    }
}

Note: This is the minimal to get it running a Extremely simple version... @aioobe is the more standard approach but requires understanding more concepts :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.