Interpreter-Fehler Zugriff aus einer anonymen Klasse

motoric18

Bekanntes Mitglied
Java:
{
JComboBox comboBox = new JComboBox();
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) 
{
    JComboBox cb = (JComboBox)arg0.getSource();
    String AggregatName = (String)cb.getSelectedItem();
			        
	if(AggregatName == "Auto")
              {
			        	
	      model.add(1,"C");

	}
// Kann das C nicht hinzufügen.

Wenn ich es außerhalb der AnoKLasse habe funktioniert dies. Bitte um Hilfe.
Was muss man machen damit man zugriff hat. Static geht leider auch nicht.

Gruß
 
Zuletzt bearbeitet von einem Moderator:
Strings vergleich man per equals.
Was ist model, wo wird das deklariert? Bekommst du nen Compilerfehler oder gehts einfach nicht? Dann liegts vermutlich an deinem Stringvergleich.
 
Hallo,
also Stringvergleich geht.

Der fehler heißt model cannot be resolved.

Wenn ich dies außerhalb der KLasse habe funktioniert dies.
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
list.setBounds(20, 43, 97, 131);
//String[] items = new String[6];
model.add(0,"A");
model.add(1,"B");
 
pulic konst()
{

{
JComboBox comboBox = new JComboBox();
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
JComboBox cb = (JComboBox)arg0.getSource();
String AggregatName = (String)cb.getSelectedItem();

if(AggregatName.equals("Auto"))
{

model.add(2,"C"); // funktioniert nicht

}

});

}






comboBox.setModel(new DefaultComboBoxModel(new String[] {"Auto1" a\u00DFe"}));
comboBox.setMaximumRowCount(12);
comboBox.setBounds(10, 11, 116, 22);
contentPanel.add(comboBox);
}


DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
list.setBounds(20, 43, 97, 131);
//String[] items = new String[6];
model.add(0,"A"); //funktiniertz
model.add(1,"B"); //funktioniert

}
 
Und jetzt das ganze nochmal in Javatags, formatiert und eingerückt damit man sieht was wohin gehört.
 

Zurück
Oben