Ich habe ein Problem und zwar läuft mein Programm ganz gut, allerdings werden die Zahlen nicht so wiedergegeben wie sie es eigentlich hätten tun sollen. Die Zahlen der Zahlenreihe werden nacheinander überschrieben, sodass ich nicht [/icode]2*2*5*5(100)[/icode] erhalte sondern lediglich nur 5. Ich bin Dankbar für jede Antwort. Hier mein Quelltext:
Mein Fehler befindet sich in der public void actionPerformed ab der while Schleife.
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Font;
public class Echo_GUI extends JFrame implements ActionListener{
private JLabel lEingabe, lAusgabe;
private JTextField tEingabe ,tAusgabe;
private JButton bEcho;
public Echo_GUI()
{
super("Echo_GUI...");
setSize(1000,800);
setResizable(false);
setLocationRelativeTo(null);
setLayout(null);
setTitle("Primzahl Berechnung");
Color c = new Color(15, 160 ,20);
getContentPane().setBackground(c);
Font schrift= new Font("Serif", Font.BOLD, 30);
lEingabe = new JLabel (" Zahl Eingeben");
lAusgabe = new JLabel (" Primzahl Faktoren");
tEingabe = new JTextField ("");
tAusgabe = new JTextField ("");
bEcho = new JButton ("Zerlegen");
lEingabe.setBounds(200,100,250,75);
lAusgabe.setBounds(580,100,300,75);
tEingabe.setBounds(200,200,250,75);
tAusgabe.setBounds(600,200,250,75);
bEcho.setBounds(350,600,300,100);
tEingabe.setFont(schrift);
tAusgabe.setFont(schrift);
lEingabe.setFont(schrift);
lAusgabe.setFont(schrift);
bEcho.setFont(schrift);
bEcho.addActionListener(this);
add(lEingabe);
add(lAusgabe);
add(tEingabe);
add(tAusgabe);
add(bEcho);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==bEcho){
String Toll = tEingabe.getText();
int pn= Integer.parseInt(Toll);
int dummy=2;
while (pn>1){
while (pn % dummy == 0){
pn/=dummy;
String AusgabeDummy = String.valueOf(dummy);
tAusgabe.setText(String.valueOf(AusgabeDummy));
}
dummy++;
}
}
}
}
Zuletzt bearbeitet von einem Moderator: