Hallo Leute,
Ich möchte ein Label aus einer anderen Klasse aus steuern.
Ich weiß, dass das mit label.setText() funktioniert nur komme ich irgendwie nicht weiter.
meine Gui
Main:
Ich glaube das Problem liegt darin,das die Gui vorher aufgerufen wird und deswegen der Text sich nicht ändert, doch wie könnte ich das am besten lösen?
Gruß
27sharp
Ich möchte ein Label aus einer anderen Klasse aus steuern.
Ich weiß, dass das mit label.setText() funktioniert nur komme ich irgendwie nicht weiter.
meine Gui
Java:
public class MainView extends JFrame {
private JPanel mitte,oben,main;
private JLabel label;
private String text;
public MainView(){
initGui();
this.setTitle("Test");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(370, 250);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private void initGui(){
main = new JPanel(new BorderLayout());
oben = new JPanel(new FlowLayout(FlowLayout.CENTER,15,10));
oben.setBorder(BorderFactory.createLineBorder(Color.black));
label = new JLabel("Text: " + text);
//Add
oben.add(label);
main.add(oben,BorderLayout.NORTH);
this.add(main);
}
public void setText(String text){
this.text = text;
}
}
Main:
Java:
public static void main(String[] args) {
MainView mv = new MainView();
mv.setText("Text");
}
Gruß
27sharp