Hallo,
Ich bin dabei, ein wenig in Grafikprogrammierung einzusteigen und mir wurde geraten, mit AWT zu beginnen. Dann Programmiere ich lustig vor mich hin, mach ein Fenster und ein paar Labels und Buttons rein.
Ich hab mit dem GridLayout gearbeitet, aber wenn ich ein TextField und einen Button einfüge macht er beides so lang wie das Fenster, ich möchte aber, dass beides etwa 3 cm lang sein soll.
Hier wär der Code:
Ich hoffe, jemand kann mir helfen, ich hab gelesen, Layoutverschachtelung könnte das Problem lösen, leider hab ich's nicht hinbekommen.
Ich bin dabei, ein wenig in Grafikprogrammierung einzusteigen und mir wurde geraten, mit AWT zu beginnen. Dann Programmiere ich lustig vor mich hin, mach ein Fenster und ein paar Labels und Buttons rein.
Ich hab mit dem GridLayout gearbeitet, aber wenn ich ein TextField und einen Button einfüge macht er beides so lang wie das Fenster, ich möchte aber, dass beides etwa 3 cm lang sein soll.
Hier wär der Code:
Java:
import java.awt.*;
import java.awt.event.*;
public class Fenster01 extends Frame implements WindowListener, ActionListener {
private static final long serialVersionUID = 1L;
Label l0, l1, l2, l3, l4, l5, l6, l7, l8, l9;
Button b1;
TextField Name;
GridLayout GridLY;
boolean loop;
Fenster01() {
this.addWindowListener(this);
this.setBackground(Color.LIGHT_GRAY);
GridLY = new GridLayout(20,1);
this.setLayout(GridLY);
l0 = new Label();
l1 = new Label(" Überschrift");
l2 = new Label();
l3 = new Label(" Langer Text, der bis zum Ende des Fensters reicht.");
l4 = new Label(" Langer Text, der bis zum Ende des Fensters reicht.");
l5 = new Label(" Langer Text, der bis zum Ende des Fensters reicht.");
l6 = new Label(" ");
l7 = new Label(" Gib deinen Namen ein: ");
loop = false;
Name = new TextField("Name");
l1.setBackground(Color.red);
b1 = new Button("Übernehmen");
b1.addActionListener(this);
l1.setFont( new Font ("Veranda", Font.BOLD, 20));
l1.setForeground(Color.yellow);
this.add(l0);
this.add(l1);
this.add(l2);
this.add(l3);
this.add(l4);
this.add(l5);
this.add(l6);
this.add(l7);
this.add(Name);
this.add(b1);
this.setSize(600, 400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
while(loop==false) {
String Name1;
Name1 = Name.getText();
l8 = new Label(" Dein Name Lautet: "+Name1);
this.add(l8);
this.setVisible(true);
loop = true;
}
}
public void windowActivated(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
}
public void windowClosing(WindowEvent arg0) { System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
}
public void windowDeiconified(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
}
public void windowOpened(WindowEvent arg0) {
}
}
Ich hoffe, jemand kann mir helfen, ich hab gelesen, Layoutverschachtelung könnte das Problem lösen, leider hab ich's nicht hinbekommen.
Zuletzt bearbeitet: