October 2017
Beginner
318 pages
7h 26m
English
Now let's take a quick look at how to add elements to our GUI from a programming standpoint. Quite possibly the simplest element that we could put inside JFrame is JLabel. Labels are responsible for containing text, and instantiating them is extremely simple. We simply tell them what text they should contain. Of course, in more complicated programs and GUIs, this text can become dynamic and may change, but for now, let's just get some text to display:
JLabel label = new JLabel("Hi. I am a GUI.");
Simply declaring that we have a JLabel class is not enough. We have not yet associated this label object in any way with our existing frame. Our frame, as you can probably tell by the vast array of methods and members it exposes, ...
Read now
Unlock full access