import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
/**
*
* Beschreibung
*
* @version 1.0 vom 18.04.2012
* @author
*/
public class Karten_Appl extends Applet {
//////////////////////////////
int anzahlbilder=8;
// Anfang Attribute
Panel cp = new Panel(null);
private Panel panLeinwand1 = new Panel(null);
private Panel panLeinwand2 = new Panel(null);
private Button playbut1 = new Button();
private Button clearbut = new Button();
private Panel panLeinwand3 = new Panel(null);
private Button butstop1 = new Button();
private Button butstop2 = new Button();
private Button butstop3 = new Button();
/////////////////////////////
MediaTracker mein_Mt = new MediaTracker(this);
MediaTracker dein_Mt = new MediaTracker(this);
MediaTracker sein_Mt = new MediaTracker(this);
MediaTracker euer_Mt = new MediaTracker(this);
Image[] bildFeld1 = new Image[anzahlbilder]; //ARRAY um Bilder aufzunehmen
Image[] bildFeld2 = new Image[anzahlbilder];
Image[] bildFeld3 = new Image[anzahlbilder];
Image[] bildFeld4 = new Image[anzahlbilder];
Thread t1, t2, t3, t4;
Karten k1,k2, k3, k4;
/////////////////////////////
private Panel panLeinwand4 = new Panel(null);
private Button butstop4 = new Button();
private Button playbut2 = new Button();
private Button playbut3 = new Button();
private Button playbut4 = new Button();
private Button playbut = new Button();
private Label label5 = new Label();
private Label label6 = new Label();
private Label label7 = new Label();
private TextField tf1 = new TextField();
private TextField tf2 = new TextField();
private TextField tfhighscore = new TextField();
private TextField tfplus = new TextField();
private Label label8 = new Label();
private Label label9 = new Label();
private Button butcheck = new Button();
// Ende Attribute
public void init() {
cp.setBounds(0, 0, 898, 588);
add(cp);
// Anfang Komponenten
/////////////////////////////
for (int i=0;i<anzahlbilder;i++){
bildFeld1[i]= this.getImage(this.getDocumentBase(),"decka"+(i)+".jpg");
bildFeld2[i]= this.getImage(this.getDocumentBase(),"deckb"+(i)+".jpg");
bildFeld3[i]= this.getImage(this.getDocumentBase(),"deckc"+(i)+".jpg");
bildFeld4[i]= this.getImage(this.getDocumentBase(),"deckd"+(i)+".jpg");
mein_Mt.addImage(bildFeld1[i],i);
dein_Mt.addImage(bildFeld2[i],i);
sein_Mt.addImage(bildFeld3[i],i);
euer_Mt.addImage(bildFeld4[i],i);
try {
mein_Mt.waitForAll();
dein_Mt.waitForAll();
sein_Mt.waitForAll();
euer_Mt.waitForAll();
} catch(InterruptedException e) { }
} // Ende von for-schleife
/////////////////////////////
panLeinwand1.setBounds(15, 23, 185, 241);
cp.add(panLeinwand1);
panLeinwand2.setBounds(229, 24, 185, 241);
cp.add(panLeinwand2);
playbut1.setBounds(54, 279, 105, 33);
playbut1.setLabel("Spielen!!!");
playbut1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playbut1_ActionPerformed(evt);
}
});
cp.add(playbut1);
clearbut.setBounds(375, 388, 179, 25);
clearbut.setLabel("Spiel neustarten (Clear All)");
clearbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
clearbut_ActionPerformed(evt);
}
});
cp.add(clearbut);
panLeinwand3.setBounds(450, 16, 185, 241);
cp.add(panLeinwand3);
butstop1.setBounds(56, 323, 105, 33);
butstop1.setLabel("Stop!");
butstop1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butstop1_ActionPerformed(evt);
}
});
cp.add(butstop1);
butstop2.setBounds(243, 323, 121, 33);
butstop2.setLabel("Stop!");
butstop2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butstop2_ActionPerformed(evt);
}
});
cp.add(butstop2);
butstop3.setBounds(478, 320, 121, 33);
butstop3.setLabel("Stop!");
butstop3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butstop3_ActionPerformed(evt);
}
});
cp.add(butstop3);
panLeinwand4.setBounds(679, 10, 185, 241);
cp.add(panLeinwand4);
butstop4.setBounds(705, 317, 105, 33);
butstop4.setLabel("Stop!");
butstop4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butstop4_ActionPerformed(evt);
}
});
cp.add(butstop4);
playbut2.setBounds(245, 281, 121, 33);
playbut2.setLabel("Spielen!!!");
playbut2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playbut2_ActionPerformed(evt);
}
});
cp.add(playbut2);
playbut3.setBounds(479, 279, 121, 33);
playbut3.setLabel("Spielen!!!");
playbut3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playbut3_ActionPerformed(evt);
}
});
cp.add(playbut3);
playbut4.setBounds(706, 275, 105, 33);
playbut4.setLabel("Spielen!!!");
playbut4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playbut4_ActionPerformed(evt);
}
});
cp.add(playbut4);
playbut.setBounds(138, 372, 209, 41);
playbut.setLabel("Jetzt Spielen!!!");
playbut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playbut_ActionPerformed(evt);
}
});
cp.add(playbut);
label5.setBounds(95, 488, 63, 25);
label5.setText("Versuche: ");
cp.add(label5);
label6.setBounds(67, 452, 50, 25);
label6.setText("Punkte: ");
cp.add(label6);
label7.setBounds(519, 432, 83, 33);
label7.setText("Ihr Highscore");
cp.add(label7);
tf1.setBounds(122, 453, 137, 25);
tf1.setText("10");
tf1.setFont(new Font("Dialog", Font.PLAIN, 14));
cp.add(tf1);
tf2.setBounds(160, 488, 49, 25);
tf2.setText("14");
tf2.setFont(new Font("Dialog", Font.PLAIN, 14));
cp.add(tf2);
tfhighscore.setBounds(411, 467, 281, 33);
tfhighscore.setForeground(Color.BLACK);
tfhighscore.setBackground(Color.GREEN);
tfhighscore.setFont(new Font("Dialog", Font.PLAIN, 20));
cp.add(tfhighscore);
tfplus.setBounds(307, 456, 65, 25);
cp.add(tfplus);
label8.setBounds(293, 454, 19, 27);
label8.setText("+");
label8.setFont(new Font("Dialog", Font.PLAIN, 16));
cp.add(label8);
label9.setBounds(308, 427, 59, 25);
label9.setText("Gewinn: ");
cp.add(label9);
butcheck.setBounds(640, 392, 105, 33);
butcheck.setLabel("button1");
butcheck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
butcheck_ActionPerformed(evt);
}
});
cp.add(butcheck);
// Ende Komponenten
}
/////////////////////////////
// Anfang Methoden
public void playbut1_ActionPerformed(ActionEvent evt) {
k1=new Karten(bildFeld1, panLeinwand1);
t1= new Thread(k1);
t1.start();
}
public void playbut2_ActionPerformed(ActionEvent evt) {
k2=new Karten(bildFeld2, panLeinwand2);
t2= new Thread(k2);
t2.start();
}
public void playbut3_ActionPerformed(ActionEvent evt) {
k3=new Karten(bildFeld3, panLeinwand3);
t3= new Thread(k3);
t3.start();
}
public void playbut4_ActionPerformed(ActionEvent evt) {
k4=new Karten(bildFeld4, panLeinwand4);
t4= new Thread(k4);
t4.start();
}
public void clearbut_ActionPerformed(ActionEvent evt) {
tf1.setText("10");
tf2.setText("14");
tfhighscore.setText("");
tfplus.setText("");
}
public void butstop1_ActionPerformed(ActionEvent evt) {
t1.stop();
}
public void butstop2_ActionPerformed(ActionEvent evt) {
t2.stop();
}
public void butstop3_ActionPerformed(ActionEvent evt) {
t3.stop();
}
public void butstop4_ActionPerformed(ActionEvent evt) {
int versuche;
versuche= Integer.valueOf(tf2.getText());
t4.stop();
versuche= versuche-1;
tf2.setText(String.valueOf(versuche));
}
public void playbut_ActionPerformed(ActionEvent evt) {
k1=new Karten(bildFeld1, panLeinwand1);
t1= new Thread(k1);
t1.start();
k2=new Karten(bildFeld2, panLeinwand2);
t2= new Thread(k2);
t2.start();
k3=new Karten(bildFeld3, panLeinwand3);
t3= new Thread(k3);
t3.start();
k4=new Karten(bildFeld4, panLeinwand4);
t4= new Thread(k4);
t4.start();
tfplus.setText("");
}
public void butcheck_ActionPerformed(ActionEvent evt) {
int punkte, erg;
punkte= Integer.valueOf(tf1.getText());
if () {
erg= punkte*100;
tf1.setText(String.valueOf(erg));
tfplus.setText(String.valueOf(erg-punkte));
}
}
// Ende Methoden
}