psykochris
Mitglied
Hi@all, muss folgendes Programm so umschreiben, dass alles in einem Applet ausgegeben wird. Da ich mich mit Java aber nur sehr bedingt auskenne habe ich keine Ahnung wie das funktioniert. Darum bitte ich um eure Hilfe. Danke im voraus.
Programm:
psykochris
ps.: Hier noch Links zu beiden von eclipse erstellten Dateien
http://www.psykochris.de/uploadfiles/Bank.java
http://www.psykochris.de/uploadfiles/Bank.class
Programm:
Code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Bank extends JDialog implements ActionListener {
private JLabel L1;
public static int Kontostand = 0;
public Bank() {
setTitle("Kontostand");
setSize(500, 500);
JPanel p = new JPanel(new BorderLayout());
L1 = new JLabel();
JButton b1 = new JButton("Close App");
b1.addActionListener(this);
p.add(b1, "North" );
JButton b2 = new JButton("Kontostand ausgeben!");
b2.addActionListener(this);
p.add(b2, "Center" );
JButton b3 = new JButton("Geld einzahlen!");
b3.addActionListener(this);
p.add(b3, "West" );
JButton b4 = new JButton("Geld abheben!");
b4.addActionListener(this);
p.add(b4, "East" );
L1 = new JLabel("Kontostand: ");
p.add(L1, "South" );
getContentPane().add(p);
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new Bank();
}
public void actionPerformed(ActionEvent arg0) {
String s = arg0.getActionCommand();
JOptionPane p = new JOptionPane();
if (s.equals("Geld einzahlen!")){
String Einzahlen = JOptionPane.showInputDialog("Wieviel wollen sie Einzahlen?");
int einzahlen;
try
{
einzahlen = Integer.parseInt(Einzahlen);
Kontostand = Kontostand + einzahlen;
}
catch (Exception e)
{
L1.setText("Sie müssen eine Zahl eingeben!");
}
}
else if (s.equals("Geld abheben!")){
String Abheben = JOptionPane.showInputDialog("Wieviel wollen sie Abheben?");
int abheben;
abheben = Integer.parseInt(Abheben);
Kontostand = Kontostand - abheben;
}
else if (s.equals ("Close App"))
System.exit(0);
else if (s.equals ("Kontostand ausgeben!"))
{
if (Kontostand < 100 )
L1.setText(Kontostand+ " €: Sie sind aber arm dran!");
else if (Kontostand >= 100 && Kontostand < 1000)
L1.setText(Kontostand+ " €: Sie hätten auch mal wieder eine Gehaltserhöhung nötig, oder?");
else if (Kontostand >= 1000 && Kontostand < 10000)
L1.setText(Kontostand+ " €: Da kann man ja neidisch werden!");
else if (Kontostand >= 10000)
L1.setText(Kontostand+ " €: Verdienen sie ihr Geld wirklich ehrlich?");
}
}
}
psykochris
ps.: Hier noch Links zu beiden von eclipse erstellten Dateien
http://www.psykochris.de/uploadfiles/Bank.java
http://www.psykochris.de/uploadfiles/Bank.class
Zuletzt bearbeitet: