Jump to content

Question for school assignment :)

botpaket

So this is the question (theory ?) 

 

It is for JLabel, JTextField, JTextArea in Java Swing Netbeans

 

1)What is the function / usage ?

2)What is the main property of those component?

3)Find the method to manage each of the property from number 2. And what parameter to manage those property also?

4)Find the method to read value from each property in number 2. and what parameter and return value is used to grab the value from those property?

5)Beside method getter-setter, what methods used regularly from each component ? what is the function of the method ? and what parameter and return value is being used?

 

sorry poor english , have to translate it from my language :(

 

i don't quiet get the questions in number 2-5

and trying to find it on google, only found the method, and no property

Link to comment
Share on other sites

Link to post
Share on other sites

1)

JLabel can show things but doesn't react to user input events.

JTextField is a single line text container, that can be used as input.

JTextArea is a multiple line text container, that can be used as input too. ​

 

2)

Main property? In what respect? It can be the text they hold, it can be the number of lines, if they are editable and so on.

 

3/4)

Assuming that the main property is the text that they're going to display, and you're talking about getters-setters stuff:

JLabel: .getText() -> returns a String, .setText(String text) -> set the JLabel internal string to the one passed in the method.

JTextField: those same methods from JLabel and should add an ActionListener to get users modifications and update the JTextField. You can configure the number of rows of that textfield.

JTextArea: same stuff as JTextField, with the addition of being able to configure number of rows.

 

5) Usually methods of those are editable flag, number or rows and columns, ...

Check those sites below to get more details:

http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html

http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextField.html

http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextArea.html 

http://docs.oracle.com/javase/tutorial/uiswing/components/text.html

http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html 

http://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html 

 

Yes, what this guy said.

 

Basically calls the Graphical User Interface (GUI) libraries in Java for text inputs. Should be called in a JFrame or a JPanel. Happy coding! Here are examples of implementing a JLabel on a JFrame on my github account , https://github.com/qamaruz/helloWorld 

Link to comment
Share on other sites

Link to post
Share on other sites

1)

JLabel can show things but doesn't react to user input events.

JTextField is a single line text container, that can be used as input.

JTextArea is a multiple line text container, that can be used as input too. ​

 

2)

Main property? In what respect? It can be the text they hold, it can be the number of lines, if they are editable and so on.

 

3/4)

Assuming that the main property is the text that they're going to display, and you're talking about getters-setters stuff:

JLabel: .getText() -> returns a String, .setText(String text) -> set the JLabel internal string to the one passed in the method.

JTextField: those same methods from JLabel and should add an ActionListener to get users modifications and update the JTextField. You can configure the number of rows of that textfield.

JTextArea: same stuff as JTextField, with the addition of being able to configure number of rows.

 

5) Usually methods of those are editable flag, number or rows and columns, ...

Check those sites below to get more details:

http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html

http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextField.html

http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextArea.html 

http://docs.oracle.com/javase/tutorial/uiswing/components/text.html

http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html 

http://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html 

1) Thank you

2) Emm, the book just said, What properties is important from the each component (JLabel , JTextField + Area)

4)There's an example in number 4, "Text : Property to show text on the menu, arrange by method setText(String text), parameter text is a to be displayed.

   They get the text using method getText() without parameter, return String value 

 

Number 4's example is just like you said? but it already been the example for number 4

is there any other method beside set and get?

 

5)What method is used beside get and set?

 

Thank you for the quick reply !

Link to comment
Share on other sites

Link to post
Share on other sites

Yes, what this guy said.

 

Basically calls the Graphical User Interface (GUI) libraries in Java for text inputs. Should be called in a JFrame or a JPanel. Happy coding! Here are examples of implementing a JLabel on a JFrame on my github account , https://github.com/qamaruz/helloWorld 

Thank you !

the link did not work ?

Link to comment
Share on other sites

Link to post
Share on other sites

The JLabel can display images too, so you have the .getIcon() and .setIcon(Icon icon); you can call the method .updateUI(), that will redraw the JLabel. You can align the content with .get(set)Horizontal(Vertical)Alignment.

With JTextField and JTextAreas you can create ActionListeners, so that can react to user input. You have those alignment methods, you can change fonts, set number of rows, get height and width, ... Check those methods on Oracle sites that I've posted before.

 

Umm actually before i post this thread, i already looked at the docs.oracle

but don't know which one is the method and property

because i  taught that all of them is method ?

 

so the getIcon setIcon etc is categorized as method right?

because method usually has () at the end?

Link to comment
Share on other sites

Link to post
Share on other sites

Yep, everything that you call with .() is a static method from a Class or a method from a Class object. If you had public variables you would access them with .variable, but that's not recommended on an object oriented approach.

On Oracle sites, you can find the Methods at Methods Summary and Fields (that is used like a variable) at Field Summary. You can check if they're from that class or inherited from their superclasses.

I see, Thank you ! :)

so the method questions for number 3-5 i think i can do that

but the number 2 (the property), in oracle sites, which one is the property?

Link to comment
Share on other sites

Link to post
Share on other sites

Well, following the answer of the example that you have posted, you can say that the ability to display text, be resized, select the font, can be used for input are properties of JTextField and JTextArea. Looks to me that the question is asking for a general property, not something specific.

Ah i see

Thank you so much for the help ! :) :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×