Q6 weapons reward for answering Java question!!
PuPazZ0
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MyApplet4 extends Applet implements ActionListener{
Button b = new Button("0");
int i;
public void init(){
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ev){
i++;
b.setLabel(i+"");
}
}
Question
If anyone can explain "b.setLabel(i+"");" --> reward 30 q6
Comment at article or PM with answers to frogs
Also the reward from him!
Comments
PERTAMAX
shit... i lost 30 q 6 tanks 🙁
increment the name of button with each click.
Costin1989 poti sa imi explici (i+""), pt ca nu inteleg de ce nu e i++ si de ce apar "" ?
Geros1988E un applet cu un buton care are initial 0 pe el; cifra creste odata cu apasarile pe el; iar linia ta fix asta face, afiseaza nr de apasari ;p
If anyone can explain "b.setLabel(i+"");" --> reward 30 q6
We do it to cast an int to strig.
Class set label just receive String, so we need change number i to string that has same meaning of i.
b.setLabel(i+"1");
waiting reward
weedoo
Increment it each time it's clicked. That would save you parsing from a String to an int.
"+" is a infix operator that concatenate two strings. In i++, ++ is a postfix operator, so it returns the value of i and then increments it.
Increment inside a loop 🙂
: ))
Why does "" appear? And why i+ instead of i++?
Successfully transferred 30 item(s) to Geros1988.
Successfully transferred 30 item(s) to costin1989.
Successfully transferred 30 item(s) to Aleatorio.
Successfully transferred 30 item(s) to Infatulus.
30 more for answering my last post.
The b.setLabel(i+"1"); changes the name of yout appplet at each interaction...
Each tiume that the listener recieves a new info, your label changes its name....