New To Java - write to JLabel

there are 2 errors in this code.

What did I wrong?

import java.awt.*;

import javax.swing.*;

publicclass writelabelextends JFrame{

publicstatic String schrijf(String s){

s ="Write this";

return s;

}

JLabel tekst;

public writelabel(){

Container ContentPane = this.getContentPane();

FlowLayout fl =new FlowLayout();

ContentPane.setLayout(fl);

ContentPane.add(tekst);

//why won't this work?

tekst.schrijf(s);

}

//why won't this work?

publicstaticvoid main(String[] args){

writelabel f =new writelabel();

f.setVisible(true);

f.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

}

[1601 byte] By [kiekeboea] at [2007-11-26 23:03:47]
# 1
Is there really a schrijf-method in the JLabel class?
Martin@Stricenta at 2007-7-10 13:56:03 > top of Java-index,Java Essentials,New To Java...
# 2

What did I wrong?

Start again.

Read your books/tutorials.

public static String schrijf(String s) {

s = "Write this";

return s;

}

here, you are combining a 'setter' with a 'getter', and it just doesn't make any sense at all.

and when you call the method

tekst.schrijf(s);

apart form the fact that setting the text of the label should be

tekst.setText(schrijf(s));

what is s?

even if you fix the above, you'll generate a NullPointerException, nowhere do

you have

= new JLabel();

so, repeating, start again, understand some basic concepts, then have another

crack at what you're trying to do

Michael_Dunna at 2007-7-10 13:56:03 > top of Java-index,Java Essentials,New To Java...