Hallo,….
Wollte ein programm schreiben mit dem man die fahrzeuge auf den straßen zählen kann ! ist noch nicht fertig, also es kommt immer der fehler das unten etwas erwartet wird. Könnt ihr mir sagen was fehlt? Und wisst ihr wie ich die ergebnisse in prozenten angeben kann?
[/code]
Wollte ein programm schreiben mit dem man die fahrzeuge auf den straßen zählen kann ! ist noch nicht fertig, also es kommt immer der fehler das unten etwas erwartet wird. Könnt ihr mir sagen was fehlt? Und wisst ihr wie ich die ergebnisse in prozenten angeben kann?
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class verkehr extends java.applet.Applet {
int anzahlPKW=0;
int anzahlKRAD=0;
int anzahlLKW=0;
String aktuell;
Button PKWTaste= new Button("PKW");
Button KRADTaste= new Button("KRAD");
Button LKWTaste= new Button("LKW");
Label anzahlPKWLabel= new Label();
Label anzahlKRADLabel= new Label();
Label anzahlLKWLabel= new Label();
Label Wahl= new Label("Bitte Wählen");
Label Wahlaktuell= new Label();
Button wählen= new Button ("Stimmabgabe");
Button Auswertung= new Button ("Auswertung");
Button Wähler= new Button ("Neuer Wähler");
public void init( ) {
// GridLayout mit 5 Zeilen und 4 Spalten
setBackground(Color.lightGray);
setLayout( new GridLayout(3,4,2,2) );
add(PKWTaste);
add(KRADTaste);
add(LKWTaste);
add(anzahlPKWLabel);
add(anzahlKRADLabel);
add(anzahlLKWLabel);
add (new Label());
add(Wahl);
add(Wahlaktuell );
add(wählen);
add (Wähler);
add (new Label());
add (new Label());
add (Auswertung);
PKWTaste.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Wahl.setText(" Sie wählen");
Wahlaktuell.setText("PKW");
aktuell=("PKW");
}
});
KRADTaste.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Wahl.setText(" Sie wählen");
Wahlaktuell.setText("KRAD");
aktuell=("KRAD");
}
});
LKWTaste.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Wahl.setText(" Sie wählen");
Wahlaktuell.setText("LKW");
aktuell=("LKW");
}
});
wählen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Wahl.setText("Sie wählten");
PKWTaste.setEnabled(false);
KRADTaste.setEnabled(false);
LKWTaste.setEnabled(false);
wählen.setEnabled(false);
if (aktuell=="PKW")
{
anzahlPKW++;
}
else
{
if(aktuell=="KRAD")
{
anzahlKRAD++;
}
else
{
if(aktuell=="LKW")
{
anzahlLKW++;
}
}
};
Wähler.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Wahl.setText(" Bitte Wählen");
Wahlaktuell.setText("");
PKWTaste.setEnabled(true);
KRADTaste.setEnabled(true);
LKWTaste.setEnabled(true);
wählen.setEnabled(true);
}
});
Auswertung.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
anzahlPKWLabel.setText (""+ anzahlPKW);
anzahlKRADLabel.setText(""+anzahlKRAD);
anzahlLKWLabel.setText(""+anzahlLKW);
Wahl.setText("Auswertung :");
PKWTaste.setEnabled(false);
KRADTaste.setEnabled(false);
LKWTaste.setEnabled(false);
Wähler.setEnabled(false);
wählen.setEnabled(false);
if( anzahlPKW> anzahlKRAD & anzahlPKW> anzahlLKW & anzahlPKW)
{
Wahlaktuell.setText("PKW");
}
else
{
if (anzahlPKW< anzahlKRAD & anzahlKRAD> anzahlLKW & anzahlKRAD)
{
Wahlaktuell.setText("KRAD");
}
else
{
if( anzahlLKW> anzahlKRAD & anzahlPKW< anzahlLKW & anzahlLKW)
{
{
Wahlaktuell.setText("Neuwahlen");
anzahlABC=0;
anzahlDEF=0;
anzahlGHI=0;
anzahlJKL=0;
anzahlABCLabel.setText("");
anzahlDEFLabel.setText("");
anzahlGHILabel.setText("");
anzahlJKLLabel.setText("");
Wähler.setEnabled(true);
}
}
}
}
}
} ) ;
} // init
} //Applet