Buttons, labels, and text areas, oh my!

339 4 0
                                        

Instead of going over an example of how to add each of the components to our GUI, I'm going to go over how they work, and then give an example them.

Lets start off with JButtons. Before our Main() object, we will declare our button

private JButton myButton = new JButton("My first button"):

And now, add this to your Main() object

add(myButton);

And now you should have a button! It wont do anything, but its nice to have.

Next are labels.

private JLabel myLabel = new JLabel("My first label!");

and just add(label);

Getting a hang of it now?

And finally, text areas.

JTextArea area = new JTextArea(1, 3);

The numbers are the size of the area, charecter wise. Be sure to add(area) to your program!

Thanks

-Steve

Java Swing GUI DevelopmentWhere stories live. Discover now