Reputation: 101
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
Upvotes: 1
Views: 275
Reputation: 4211
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 :)
Upvotes: 0
Reputation: 420951
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();
}
});
}
}
Upvotes: 2