Ich arbeite am folgenden Code. Leider zeigt er mir zwar das Fenster aber es zeigt mir keinen Inhalt an und wenn ichs schließen ( das Fenster / klick auf Kreuz rechts oben ) will, dann passiert nichts. Was kann ich machen?
Edit von L-ectron-X: Titel Aussage kräftiger gemacht.
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class prog extends Frame{
Panel panel1, panel2;
Button start, stop, anleitung;
GridBagLayout gridbag = new GridBagLayout();
TextField t_user, t_port, t_host, t_pw;
public prog(String title){
super(title);
panel1 = new Panel();
panel1.setLayout(gridbag);
panel1.setBackground(Color.red);
panel1.setFont(new Font("Helvetica",Font.BOLD, 24));
Label lab = new Label();
lab.setFont(new Font("Helvetica", Font.BOLD, 24));
lab.setBackground(Color.green);
lab.setForeground(Color.red);
lab.setText("MySQL - Connector Version 0.1");
constrain(panel1, lab, 0, 0, 6, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER);
panel2 = new Panel();
panel2.setLayout(gridbag);
panel2.setBackground(Color.blue);
Label lab2 = new Label();
lab2.setFont(new Font("Arial", Font.BOLD, 30));
lab2.setBackground(Color.blue);
lab2.setForeground(Color.red);
lab2.setText("TEST TEST TEST");
constrain(panel2, lab2, 0, 2, 6, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER);
this.setLayout(gridbag);
constrain(this, panel1, 0, 0, 9, 2, GridBagConstraints.NONE, GridBagConstraints.NORTH);
constrain(this, panel2, 0, 2, 9, 7, GridBagConstraints.NONE, GridBagConstraints.WEST);
}
public void constrain (Container container, Component component, int gridx, int gridy,
int gridw, int gridh, int fill, int anchor, double w_x, double w_y,
int top, int left, int bottom, int right){
GridBagConstraints c = new GridBagConstraints();
c.gridx = gridx; c.gridy = gridy;
c.gridwidth = gridw; c.gridheight = gridh;
c.fill = fill; c.anchor = anchor;
c.weightx = w_x; c.weighty = w_y;
if (top+bottom+left+right > 0)
container.add(component, c);
}
public void constrain (Container container, Component component,
int gridx, int gridy, int gridw, int gridh){
constrain(container, component, gridx, gridy, gridw, gridh,
GridBagConstraints.NONE, GridBagConstraints.NORTHWEST,
0.0, 0.0, 0, 0, 0, 0);
}
public void constrain (Container container, Component component,
int gridx, int gridy, int gridw, int gridh, int fill, int anchor){
constrain(container, component, gridx, gridy, gridw, gridh,
fill, anchor, 0.0, 0.0, 0, 0, 0, 0);
}
public static void main(String[] args){
Frame f = new prog("MySQL - Connector Version 0.1");
f.pack();
f.show();
}
}
Edit von L-ectron-X: Titel Aussage kräftiger gemacht.