R
Ro0kie
Gast
Liebes Java-Forum!
Ich habe schon wieder Probleme mit meinem Applet nur dieses mal funktionieren weder
noch
!:wuerg:
Obwohl "mit Joker" angehakt ist wird es nicht angezeigt und der rest erklärt sich von selbst...
Ich habe die Methoden
und
schon an ziemlich jeder Stelle ausprobiert
Jede Möglcihe Idee wäre hilfreich !
Danke im vorhinein
MfG Ro0kie
Ich habe schon wieder Probleme mit meinem Applet nur dieses mal funktionieren weder
Code:
validate()
Code:
repaint()
Obwohl "mit Joker" angehakt ist wird es nicht angezeigt und der rest erklärt sich von selbst...
Java:
import javax.swing.JApplet;
/**
* Applet,welches dem Benutzer einen Lottotipp gibt.
*
* @author Martin S
* @version 2011-05-10
*/
public class LottotippApplet extends JApplet {
/**
* Methode,welche nach dem laden des Applets gestartet wird.
*/
public void init(){
add (new LottotippPanel());
}
}
Java:
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
/**
* @author Martin
*
*/
public class Lottotipp {
private Set<Integer> tipp = new TreeSet<Integer>();
public String getLottotipp(){
while(tipp.size()<6){
tipp.add((int) (Math.random()*45+1));
}
String txt = "";
//For-each Schleife
for(Integer i : tipp) {
txt += i + ", ";
}
return txt.substring(0, txt.length() - 2);
}
public String getJoker(){
String txt2 = "";
//Zusatztzahl erzeugen
int joker = (int) (Math.random()*45+1);
//Prfen ob Zusatztzahl schon vorhanden
while(tipp.contains(joker)){
joker = (int) (Math.random()*45+1);
}
//TreeSet zerlegen und in String wandeln
Iterator it =tipp.iterator();
while(it.hasNext()){
txt2=txt2 +it.next();
txt2 = txt2 + ", ";
}
txt2 =txt2 + "| " + joker;
return txt2;
}
}
Java:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Set;
import java.util.TreeSet;
/**
* Panel für das Applet "LottotippApplet".
*
* @author Martin Suschny
* @version 2011-05-10
*/
public class LottotippPanel extends JPanel {
private JButton newtipp;
private JCheckBox joker;
private JTextField anzeige;
private JPanel panel;
public LottotippPanel(){
//Layot setzen
this.setLayout(new GridLayout(2,1));
//Grafische Elemente init und hinzufügen.
newtipp = new JButton("Neuer Tipp");
anzeige = new JTextField();
joker = new JCheckBox("mit Joker");
//Panel
panel = new JPanel();
panel.setLayout (new FlowLayout());
panel.add (newtipp);
panel.add (joker);
add (anzeige);
add (panel);
//Grafische Elemente beim ActionLister regestrieren.
LottotippAction h = new LottotippAction();
newtipp.addActionListener(h);
anzeige.addActionListener(h);
joker.addActionListener(h);
}
public class LottotippAction implements ActionListener{
public void actionPerformed(ActionEvent e){
Lottotipp tipp = new Lottotipp();
if(e.getSource()==newtipp){
String txt = tipp.getLottotipp();
anzeige.setText(txt);
}
if((e.getSource()==newtipp) &&(joker.isSelected()==true)){
String txt2 = tipp.getJoker();
anzeige.setText(txt2);
}
}
}
}
Code:
validate()
Code:
repaint()
Jede Möglcihe Idee wäre hilfreich !
Danke im vorhinein
MfG Ro0kie