Hallo,
ich bekomme hier einen Fehler in Zeile 68:
Der Fehler lautet: The Method add(Component) in the type Container is not applicable for the arguments (Rectangle)
Kein Plan was das bedeuten soll, vielleicht hat jemand eine Idee.
ich bekomme hier einen Fehler in Zeile 68:
Der Fehler lautet: The Method add(Component) in the type Container is not applicable for the arguments (Rectangle)
Kein Plan was das bedeuten soll, vielleicht hat jemand eine Idee.
Code:
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Frame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel panel;
private JTextField textField;
private JLabel label;
public static void main(String[]args){
new Frame();
}
Frame(){
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(312,214));
panel = new JPanel(null);
label = new JLabel("Test");
label.setBounds(3,4,80,20);
label.setHorizontalAlignment(JLabel.LEFT);
label.setBorder(BorderFactory.createLineBorder(Color.black));
panel.add(label);
JButton button = new JButton();
button.setBounds(103, 94, 100, 20);
button.setHorizontalAlignment(JLabel.CENTER);
button.setText("Button");
add(button);
//ActionListener für den Button;
AListener aListener = new AListener(this);
button.addActionListener((ActionListener) aListener);
textField = new JTextField();
textField.setBounds (103,64,100,20);
textField.setHorizontalAlignment(JLabel.RIGHT);
panel.add(textField);
JTextField textField2 = new JTextField();
textField2.setBounds(223,74,50,20);
textField2.setHorizontalAlignment(JLabel.RIGHT);
panel.add(textField2);
FListener fListener = new FListener(this);
textField.addFocusListener(fListener);
Rectangle ecke = new Rectangle();
ecke.setBounds(23,64,70,30);
panel.add(ecke);
add(panel);
pack();
setVisible(true);
}
public JTextField getTextField(){
return textField;
}
public JTextField getTextField1() {
// TODO Auto-generated method stub
return null;
}
public void switchLabelText() {
if (label.getText().equals("Test")){
label.setText("AlernativText");
} else {
label.setText("Test");
}
}
}