To add Swing framework elements at runtime, you need to have a JFrame to add the elements to. A JFrame is just a window, like any other window you use (and just like NetBeans has), and it has a method called add(Component comp)
. The parameter is whichever Swing or AWT component you want to add to the JFrame. Here is some sample code to get you started:
// This line creates a new window to display the UI elements:
JFrame window = new JFrame("Window title goes here");
// Set a size for the window:
window.setSize(600, 400);
// Make the entire program close when the window closes:
// (Prevents unintentional background running)
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// This makes it so we can position elements freely:
window.setLayout(null);
// Create a new button:
JButton b4 = new JButton("ok");
// Set the location and size of the button:
b4.setLocation(10, 10);
b4.setSize(100, 26);
// Add the button to the window:
window.add(b4);
// Make the window visible (this is the only way to show the window):
window.setVisible(true);
Hopefully, this helps you out! I remember when I started Java, and I would highly recommend getting as good as possible at non-GUI related stuff first, but if you are ready for Swing, then the code above should work. Best of luck!