Learn to Code via Tutorials on Repl.it!

← Back to all posts
Java Swing Tutorial Day 2. LEARN HOW TO MAKE A GUI
h
EpicGamer007

Java Swing Tutorial Day 2

G'Day Again fellow replers. It seems that there really is some people who enjoyed learning java swing.
So I will continue teaching it!

Swing!

(One of) The java libraries for making Cross-platform Desktop Applications.

Previous Tutorials:
  • Day 1: We learned how to make a JFrame and button there!

The topics for today are...

JCOMPONENTS

JComponents are components included in the java library.

Unsurprisingly, hey all start with a J

We will be going over more JComponents in the future, but for today, we will be going over the following.

First up...

JCheckBox!

A checkbox is just a box which can be selected or not be selected indicated with a check. It is Extremely simple to use.

How to use JCheckBox!:

This is how simple it is to use a JCheckBox. You can get all the information about the methods and constructors here.

Up next...

JLabel!

A JLabel is just a label which holds a string of characters and you can print that almost anywhere in a frame.
It is usually used to show the user information

Here is how to create a JLabel and to use it.

Note: From here on out, I will not include the code other than what is required(The JComponent we are going over)

That is how simple it is to use a JLabel! You can use that to print information to the gui!

Check out the doc here!

And now the final JComponent we will be going over...

JTextField!

A JTextField is pretty much a text field. The user can type in information in it.

A text field also fires action events when the user presses enter.

In this example, pretend we are writing a chat client...

That is how simple it is to use a JTextField! Incredibly easily!
Check out the doc as well!

Well, that is it for this tutorial!

I hope you enjoyed and learned something new. You can try these JComponents in a new java swing project.

Please give feedback in the comments.

Thank you!

Voters
Gadou
acohenwolcott
ClaudinePugal
AsmaPatel
EGGSistence
bluefiredubby
Highwayman
TheForArkLD
IvanChang111
Jakman
Comments
hotnewtop
EpicGamer007

@Highwayman , @TheForArkLD , @IvanChang111, @Jakman

Tutorial 3 is out: Java Swing tutorial day 3

If you would not like to get updates for this tutorial series, please let me know in the comments.

AVAJAMES

Can there be an update for this tutorial series? It would be much appreciated!

EpicGamer007

@AVAJAMES wdym?
edit: I ended it a bit after this, check out my other posts by clicking on my profile and going to the posts tab. filter by tutorials with ctrl/cmd-f

AVAJAMES

@EpicGamer007 Oh, ok. thx. (I'm new at this!)