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]

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