Somewhere going through java good articles, I found that such code compiles perfectly.
public int myMethod(){
http://www.google.com
return 1;
}
description says that http:
word will be treated as label and //www.google.com
as comment
I am not getting how Java Label is useful outside loop? Under what situation Java Label outside loop should be used?
The fundamental difference between the two is that JLabel allows the label to be composed of text, graphics, or both, while the old Label class only allowed simple text labels. This is a powerful enhancement, making it very simple to add graphics to your user interface.
It is impossible to make an editable label as it exists. You can use a jTextField with no border and same background as the JFrame. Having said that, you can add a KeyListener to your JLabel and update your label's text depending on the key that was pressed.
add(label); final JButton remove = new JButton("Remove label"); leftPanel. add(remove); add. addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rightPanel. remove(label); } });
Here is one benefit of using labels in Java:
block:
{
// some code
if(condition) break block;
// rest of code that won't be executed if condition is true
}
Another usage with nested-loops:
outterLoop: for(int i = 0; i < 10; i++)
{
while(condition)
{
// some code
if(someConditon) break outterLoop; // break the for-loop
if(anotherConditon) break; // break the while-loop
// another code
}
// more code
}
or:
outterLoop: for(int i = 0; i < 10; i++)
{
while(condition)
{
// some code
if(someConditon) continue outterLoop; // go to the next iteration of the for-loop
if(anotherConditon) continue; // go to the next iteration of the while-loop
// another code
}
// more code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With