T
thorstenm.
Gast
Hallo, ich habe vor winen Taschenrechner mit grafischer oberfläche zu programmieren.
leider funktionieren die Buttons nicht wie ich will,
hier nur 3 im programm, ende funktioniert gut, die anderen beiden entweder, oder...
wo liegt mein problem?
danke Thorsten
leider funktionieren die Buttons nicht wie ich will,
hier nur 3 im programm, ende funktioniert gut, die anderen beiden entweder, oder...
wo liegt mein problem?
danke Thorsten
Code:
import java.awt.*;
import java.awt.event.*;
public class Fenster1 extends Frame implements ActionListener
{
private final int vonoben=35; // Abstand oben
private final int vonlinks=5; // Abstand links
TextField t_Zahl;
TextField t_ein;
Button b_ausgabe= new Button ("=");
Button b_ende = new Button();
Button b_minus = new Button("-");
Button b_mal = new Button("*");
Button b_plus = new Button("+");
Button b_get = new Button("/");
Button b_eingabe= new Button("-->");
double erg = 0.0;
double zahl1 = 0.0;
double zahl2 = 0.0;
public Fenster1()
{
setBackground(Color.LIGHT_GRAY);
setForeground(Color.BLACK);
setLayout(null);
setTitle(">>> Taschenrechner <<<");
setSize(300,400);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
b_ausgabe.setBounds(vonlinks+230,vonoben+150,40,20);
b_ausgabe.addActionListener(this);
add(b_ausgabe);
b_mal.setBounds(vonlinks+230,vonoben+75,40,20);
b_mal.addActionListener(this);
add(b_mal);
Button b_get = new Button("/");
b_get.setBounds(vonlinks+180,vonoben+75,40,20);
b_get.addActionListener(this);
add(b_get);
Button b_plus = new Button("+");
b_plus.setBounds(vonlinks+230,vonoben+20,40,20);
b_plus.addActionListener(this);
add(b_plus);
Button b_minus = new Button("-");
b_minus.setBounds(vonlinks+180,vonoben+20,40,20);
b_minus.addActionListener(this);
add(b_minus);
b_ende.setLabel("Ende");
b_ende.setBounds(vonlinks+150,vonoben+240,100,40);
b_ende.addActionListener(this);
add(b_ende);
b_eingabe.setBounds(vonlinks+230,vonoben+120,40,20);
b_eingabe.addActionListener(this);
add(b_eingabe);
t_ein = new TextField(" ");
t_ein.setBounds(vonlinks,vonoben+120,150,20);
add(t_ein);
t_Zahl = new TextField();
t_Zahl.setBounds(vonlinks,vonoben+150,150,20);
add(t_Zahl);
setVisible(true);
}// end Fenster1
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b_minus)
{
String s = new String(t_ein.getText());
zahl2 = Double.parseDouble(s);
System.out.println(zahl2);
}//end b_ende
if(e.getSource()==b_mal)
{
String s = new String(t_ein.getText());
zahl2 = Double.parseDouble(s);
System.out.println(zahl2);
}//end b_ende
if(e.getSource()==b_ende)
{
dispose();
System.exit(0);
}
}// end action performed
}//end class