learning java

J

Jacky Luk

import java.awt.Graphics;


public class test1 extends java.applet.Applet {
//@Override
private String str;
private String str2;
public test1()
{
str = "come on";
str2 = " my friend";
}
public void init()
{
str.concat(str2);
}

public void paint(Graphics g) {

g.drawString("Hello from java!", 60, 30);
g.drawString(str, 100, 100);
}
}

How come str should be "come on my friend" instead of just "come on"? but
the applet just displayed "come on" without "my friend", so what happened?
Thanks
Jack
 
A

Andrew Thompson

Jacky Luk wrote:
.....
public void init()
{
str.concat(str2);

This is 'throwing away the result', try instead..
str = str.concat(str2);
....

Andrew T.
 
J

Jacky Luk

perfect fit! thanks
Jack

Andrew Thompson said:
Jacky Luk wrote:
....

This is 'throwing away the result', try instead..
str = str.concat(str2);
...

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top