hallo
ich kann nicht einmal eine vernünftige GUI(AWT/SWING) entwickeln, dies obwohl ich insgesamt 4 Semester an einer
Uni studiert habe.
Schade…
Beispiel:
import java.awt.event.*;
public class GUI extends Panel implements ActionListener {
Font font;
GridBagLayout gbl;
GridBagConstraint gbc;
Label VornameLabel;
Label NachnameLabel;
Label GehaltLabel;
Label AbteilungLabel;
TextField VornameTextField;
TextField NachnameTextField;
TextField GehaltTextField;
TextField AbteilungTextField;
Label AGBLabel;
TextArea AGBTextArea;
Button AbbrechenButton;
Button OkButton;
public void initComponents() {
font = new Font ("SansSerif",Font .PLAIN,22);
gbl = new GridBagLayout();
gbc = new GridBagConstraint();
AGBLabel = new Label("Vorname");
AGBLabel.setFont(font);
AGBLabel.setForeground(Color.BLACK);
AGBLabel.setBackground(Color.LIGHT_GRAY);
VornameLabel = new Label("Vorname");
VornameLabel.setFont(font);
VornameLabel.setForeground(Color.BLACK);
VornameLabel.setBackground(Color.LIGHT_GRAY);
NachnameLabel = new Label("Nachname");
NachnameLabel.setFont(font);
NachnameLabel.setForeground(Color.BLACK);
NachnameLabel.setBackground(Color.LIGHT_GRAY);
GehaltLabel = new Label("Gehalt");
GehaltLabel.setFont(font);
GehaltLabel.setForeground(Color.BLACK);
GehaltLabel.setBackground(Color.LIGHT_GRAY);
AbteilungLabel = new Label("Abteilung");
AbteilungLabel.setFont(font);
AbteilungLabel.setForeground(Color.BLACK);
AbteilungLabel.setBackground(Color.LIGHT_GRAY);
VornameTextField = new TextField("",20);
VornameTextField.setFont(font);
VornameTextField.setForeground(Color.BLACK);
VornameTextField.setBackground(Color.BLUE);
NachnameTextField = new TextField("",20);
NachnameTextField.setFont(font);
NachnameTextField.setForeground(Color.BLACK);
NachnameTextField.setBackground(Color.BLUE);
GehaltTextField = new TextField("",20);
GehaltTextField.setFont(font);
GehaltTextField.setForeground(Color.BLACK);
GehaltTextField.setBackground(Color.BLUE);
AbteilungTextField = new TextField("",20);
AbteilungTextField.setFont(font);
AbteilungTextField.setForeground(Color.BLACK);
AbteilungTextField.setBackground(Color.BLUE);
AGBTextArea = new TextArea(5,15);
AGBTextArea.setFont(font);
AGBTextArea.setForeground(Color.BLACK);
AGBTextArea.setBackground(Color.BLUE);
AGBTextArea.append("Hello World..");
AbbrechenButton = new Button("Abbrechen");
AbbrechenButton.setFont(font);
AbbrechenButton.setForeground(Color.BLACK);
AbbrechenButton.setBackground(Color.BLUE);
AbbrechenButton.addActionListener(new CloseListener());
OkButton = new Button("Ok");
OkButton.setFont(font);
OkButton.setForeground(Color.BLACK);
OkButton.setBackground(Color.BLUE);
OkButton.addActionListener(new CheckListener());
}
public GUI() {
initComponents();
Panel VornamePanel = new Panel();
VornamePanel.setLayout(new GridLayout(1,2));
VornamePanel.add(VornameLabel);
VornamePanel.add(VornameTextField);
Panel NachnamePanel = new Panel();
NachnamePanel.setLayout(new GridLayout(1,2));
NachnamePanel.add(NachnameLabel);
NachnamePanel.add(NachnameTextField);
Panel GehaltPanel = new Panel();
GehaltPanel.setLayout(new GridLayout(1,2));
GehaltPanel.add(GehaltLabel);
GehaltPanel.add(GehaltTextField);
Panel AbteilungPanel = new Panel();
AbteilungPanel.setLayout(new GridLayout(1,2));
AbteilungPanel.add(AbteilungLabel);
AbteilungPanel.add(AbteilungTextField);
Panel PersonPanel = new Panel();
PersonPanel.setLayout(new GridLayout(2,2,80,40));
PersonPanel.add(VornamePanel);
PersonPanel.add(NachnamePanel);
PersonPanel.add(GehaltPanel);
PersonPanel.add(AbteilungPanel);
Panel AGBPanel = new Panel();
AGBPanel.setLayout(new BorderLayout());
AGBPanel.add(AGBLabel,BorderLayout.NORTH);
AGBPanel.add(AGBTextArea,BorderLayout.CENTER);
Panel ButtonPanel = new Panel();
ButtonPanel.setLayout(new GridLayout(1,2,30,0));
ButtonPanel.add(AbbrechenButton);
ButtonPanel.add(OkButton);
//GridBagLayout anwenden
Panel OOPanel = new Panel();
OOPanel.setLayout(gbl);
gbc = makeGBC(0,0,6,3);
gbc.insets = new Insets(70,50,0,0);
gbl.setConstraint(PersonPanel,gbc);
OOPanel.add(PersonPanel);
add(OOPanel);
}
public GridBagConstraint makeGBC(int x, int y, int h, int w) {
GridBagConstraint gbc = new GridBagConstraint();
gbc.gridx=x;
gbc.gridy=y;
gbc.gridheigth=h;
gbc.gridwidth=w;
return gbc;
}
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (cmd.equal("Abbrechen")) {
System.exit(0);
}else {
//Aktion definieren
}
}
}//End Of Class```
Cool!!
;):o);)
:p;P;P
:o:o:o