A
anfaenger123
Gast
Hallo,
irgendwie habe ich in dem folgenden Code etwas falsch. Eclipse erkennt nämlich setLayout (Z. 15) und add (Z. 27) nicht. Er sagt immer "The method setLayout(GridBagLayout) is undefined for the type Layout" bzw. "The method add(Button) is undefined for the type Layout". Was stimmt denn daran nicht?
irgendwie habe ich in dem folgenden Code etwas falsch. Eclipse erkennt nämlich setLayout (Z. 15) und add (Z. 27) nicht. Er sagt immer "The method setLayout(GridBagLayout) is undefined for the type Layout" bzw. "The method add(Button) is undefined for the type Layout". Was stimmt denn daran nicht?
Java:
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
class Layout {
public static void main(String[] args) {
JFrame mainFrame = new JFrame("Bilder");
mainFrame.setSize(500, 500);
mainFrame.setVisible(true);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints eig = new GridBagConstraints();
setLayout(gridbag);
Button b = new Button("Testbutton");
eig.gridx = 0;
eig.gridy = 0;
eig.gridwidth = 1;
eig.gridheight = 1;
eig.weightx = 30;
eig.weighty = 30;
eig.fill = GridBagConstraints.NONE;
eig.anchor = GridBagConstraints.CENTER;
gridbag.setConstraints(b, eig);
add(b);
}
}