yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Java GUI Lesson 5 | Three more swing components


3m read
·Nov 3, 2024

Hey, this is Maads 101. My name is Jake, and welcome to your fifth Java GUI tutorial. Now, I'm not really going to be building like a whole program here. I'm just going to be talking about three more swing components, which are the password field, text area, and checkboxes. I'm just going to be showing what those are so you can incorporate them into your own program.

So, I'm going to first import javax.swing and java.awt. All right, now we make this extend JFrame. Okay, so now I'm going to be making our components.

private JPasswordField pass;
private JTextArea area;
private JCheckBox check1;
private JCheckBox check2;

I'll call it pass and yeah, JPasswordField. And what that is, so you can't see what someone's typing. Yeah, I guess that's how you spell star. So that's like if you type text into it, it's just like starred, is what that is.

Private JTextArea, call that area, and that's just like a larger kind of JTextField. So, and private JCheckBox check1, just a checkbox. private JCheckBox check2, not I'm going to be adding. I'm not going to be adding any event handling here, any really functionality to it. I'm just going to be adding them to a frame and showing you what they are and what they look like.

So, time to make the constructor public.

public Second() {
    setLayout(new FlowLayout());
}

I'll just, I'm just going to do the new flow layout because there's no need to position them because, yeah, we're not really going to be doing anything with them. So, I'm just going to use a default layout.

setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Okay, so pass = new JPasswordField(); and I'm going to pass the string in there just like a bunch of stuff. It doesn't really matter; it's going to be starred and all. Just to show you that it's starred.

area = new JTextArea("I'm a text area");
check1 = new JCheckBox("Check me");
check2 = new JCheckBox("Check me too");

So, add pass, add area, add check1, add check2. All right, and that's really all we need to do. But I'm just going to be mentioning about this JTextArea. There are some very useful methods you can call with it, which are, I'm just going to be explaining what they are.

area.setText("Text");

The string you pass in there will be what you want to set the text as.

area.getText();

Which returns whatever is in the JTextArea.

area.append("New Text");

And that will append it or add something extra to it. So that's some stuff you can do with the JTextArea.

I'm not going to be really going all in depth about anything in this tutorial. I'm just going to be showing what these components are, so then I'm just going to set visible true and go.

setVisible(true);

Okay, so yeah, it just put them all at the top. So, this text area says, "I'm a text area." This is the JPasswordField, so whatever I type in here is, um, is starred. For all you know, I could have typed the Maads 101 password in there, and you wouldn't be able to see what it is.

These checkboxes are just, you can check them, uncheck them, and I didn't add action listeners, so they don't do anything right now. But yeah, so those are just some three components that you can play around with if you want.

So, thank you for watching Maads 101. Subscribe, and goodbye.

More Articles

View All
IF YOU Want To Make A MILLION DOLLARS - WATCH THIS!|Kevin O'Leary
First of all, you know, I guess I should apologize. I haven’t been back on the tube in weeks because I’ve been crazy busy shooting season 12 of Shark Tank in itself, which is an extraordinary feat. I gotta do a big shout out to the cast and crew on this b…
How To Use The 2023 Recession To Build Wealth
Despite the 2023 economy looking pretty shaky, with high inflation, the Federal Reserve raising rates, and the stock market suffering over the past 12 months or so, many of the world’s best investors have been busy buying into the market. While most other…
IPFS, CoinList, and the Filecoin ICO with Juan Benet and Dalton Caldwell
Hey, this is Craig Cannon, and you’re listening to Y Combinator’s podcast. Today’s episode is with Dalton Caldwell, who’s a partner at YC and Wamba Net, who’s the founder of Protocol Labs, a YC company that’s working on IPFS, Filecoin, and CoinList. If y…
Volume with cross sections perpendicular to y-axis | AP Calculus AB | Khan Academy
Let R be the region enclosed by y is equal to four times the square root of nine minus x and the axes in the first quadrant. We can see that region R, and gray right over here, region R is the base of a solid. For each y value, the cross section of the so…
Dividing fractions and whole number word problems
We are told that Billy has one fourth of a pound of trail mix. He wants to share it equally between himself and his brother. How much trail mix would they each get? So pause this video and try to figure that out. All right, now let’s work through this to…
How I Invest In Crypto & DeFi
I thought it’s such a piece of trash. What a stupid idea, and it did a ton. I’m going to go to every beach on Earth. I just want to go to every beach on Earth, and I did. It took me three years, and at the end of it, I was bored out of my [ __ ] mind. I m…