import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.applet.*;
import java.util.Timer;
import java.util.TimerTask;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
public class findnumbers extends JApplet {
private JButton[] jbt;
private int zaehler;
private JPanel jPan = new JPanel();
private JPanel jPan2 = new JPanel();
private JPanel jPanpbar = new JPanel();
private JPanel jPanpbarFlowLayout = new JPanel();
private JPanel jPanpersonalBest = new JPanel();
private JPanel ParameterPan = new JPanel();
private JPanel ParameterPan2 = new JPanel();
private JPanel ParameterPan3 = new JPanel();
private JPanel ParameterPan4 = new JPanel();
private JPanel mainPan = new JPanel();
private JButton jbtStart = new JButton("Start"){
public Dimension getPreferredSize(){
return new Dimension(100,25);
}
};
private JLabel zeitlbl = new JLabel("Time",SwingConstants.CENTER);
private JLabel zeitlbl2 = new JLabel("Test",SwingConstants.CENTER);
private JLabel personalBest1 = new JLabel(" ",SwingConstants.CENTER);
private JLabel personalBest2 = new JLabel(" ",SwingConstants.CENTER);
private JLabel personalBest3 = new JLabel(" ");
private JLabel personalBest4 = new JLabel(" ");
private JLabel personalBest5 = new JLabel(" ");
private final static int NUMBER_OF_RIGHTSOUNDS = 9;
private final static int NUMBER_OF_WRONGSOUNDS = 6;
private AudioClip[] audioRight = new AudioClip[NUMBER_OF_RIGHTSOUNDS];
private AudioClip[] audioWrong = new AudioClip[NUMBER_OF_WRONGSOUNDS];
private long aTime,bTime,cTime;
private boolean isStandalone = false;
private int btimeaktintern = 0;
private int runtime;
private Color sbuttonbgc = Color.decode("#" + "888522");
private Color sbuttonbgcp = Color.decode("#" + "775544");
private int nfieldsoundr = 0;
private int nfieldsoundw = 0;
private int fsbolt = 1;
private int nfieldfs= 20;
private Color nfieldbgc = Color.decode("#" + "F5FF9C");
private Color nfieldbgcpr = Color.decode("#" + "000066");
private Color nfieldbgcpw = Color.decode("#" + "FF0000");
private Color nfieldfc= Color.decode("#" + "000000");
private Color nfieldfcp = Color.decode("#" + "FFFFFF");
private Color efieldbgc= Color.decode("#" + "555555");
private Color sbuttonfc= Color.decode("#" + "000000");
private Color tfieldbgc= Color.decode("#" + "eeeeee");
private Color tfieldfc= Color.decode("#" + "000000");
private int bgonline = 1;
private int msize = 6;
private double format2 = (double)msize;
private int z= (int)((format2*format2+0.5)*8.0/10.0);
private int l=msize*msize - z;
private boolean[] a = new boolean[l+z];
private int[] b = new int[z];
private JProgressBar pbarConcentration;
private int pbarConcentrationTime=0;
private int pbarConcentrationTimeUL = 1000;
private Timer timer;
private Timer timerpbar;
private TimerTask timertask;
private TimerTask timerpbartask;
private boolean isstarted = false;
public void init(){
if (!isStandalone) {
sbuttonbgc = Color.decode("#" + getParameter("sbuttonbgc"));
sbuttonbgcp = Color.decode("#" + getParameter("sbuttonbgcp"));
nfieldsoundr =Integer.parseInt(getParameter("nfieldsoundr"));
nfieldsoundw = Integer.parseInt(getParameter("nfieldsoundw"));
fsbolt = Integer.parseInt(getParameter("fsbolt"));
nfieldfs= Integer.parseInt(getParameter("nfieldfs"));
nfieldbgc = Color.decode("#" + getParameter("nfieldbgc"));
nfieldbgcpr = Color.decode("#" + getParameter("nfieldbgcpr"));
nfieldbgcpw = Color.decode("#" + getParameter("nfieldbgcpw"));
nfieldfc= Color.decode("#" + getParameter("nfieldfc"));
nfieldfcp = Color.decode("#" + getParameter("nfieldfcp"));
efieldbgc= Color.decode("#" + getParameter("efieldbgc"));
sbuttonfc= Color.decode("#" + getParameter("sbuttonfc"));
tfieldbgc= Color.decode("#" + getParameter("tfieldbgc"));
tfieldfc= Color.decode("#" + getParameter("tfieldfc"));
bgonline = Integer.parseInt(getParameter("bgonline"));
btimeaktintern = Integer.parseInt(getParameter("btimeakt"));
msize = Integer.parseInt(getParameter("msize"));
format2 = (double)msize;
z= (int)((format2*format2+0.5)*8.0/10.0);
l=msize*msize - z;
for (int i = 0; i < NUMBER_OF_RIGHTSOUNDS; i++) {
audioRight[i] = getAudioClip(getDocumentBase(), "audio/right" + i +".wav");
}
for (int i = 0; i < NUMBER_OF_WRONGSOUNDS; i++) {
audioWrong[i] = getAudioClip(getDocumentBase(), "audio/wrong" + i + ".wav");
}
}
personalBest1.setForeground(nfieldfc);
personalBest1.setFont(new java.awt.Font("Arial", 0, nfieldfs-2)); // NOI18N(nfieldfs);
personalBest2.setForeground(nfieldfc);
personalBest2.setFont(new java.awt.Font("Arial", 0, nfieldfs-2)); // NOI18N(nfieldfs);
jbt = new JButton[z+l];
jPan.setLayout(new GridLayout(msize,msize,1,1));
jPan.setBackground(efieldbgc);
for (int zi = 0; zi<z+l;zi++){
jbt[zi] = new JButton();
zButton(zi, fsbolt, nfieldfs, nfieldbgc, nfieldfc);
if ((nfieldsoundr == 0) && (nfieldsoundw == 0)) {
jbt[zi].addMouseListener(new zjbtNoSoundMouseListener ());
}
else if ((nfieldsoundr == 0) && (nfieldsoundw > 0)){
jbt[zi].addMouseListener(new zjbtNoRightSoundMouseListener ());
}
else {
jbt[zi].addMouseListener(new zjbtMouseListener ());
}
jPan.add(jbt[zi]);
}
zeitlbl.setOpaque(true);
zeitlbl.setBackground(tfieldbgc);
zeitlbl.setFont(new Font("Arial", Font.BOLD, 14));
zeitlbl.setForeground(tfieldfc);
zeitlbl2.setBackground(tfieldbgc);
zeitlbl2.setOpaque(true);
jbtStart.setBorder(BorderFactory.createRaisedBevelBorder());
jbtStart.setFocusPainted(false);
jbtStart.setBackground(sbuttonbgc);
jbtStart.setForeground(sbuttonfc);
jbtStart.setMnemonic(KeyEvent.VK_S);
jbtStart.addActionListener(new jbtStartActionListener ());
UIManager.put("Button.select", sbuttonbgcp);
ParameterPan.setLayout(new BorderLayout(0,0));
pbarConcentration = new JProgressBar(0, pbarConcentrationTimeUL);
pbarConcentration.setBorderPainted(true);
pbarConcentration.setForeground(nfieldbgcpw);
jPanpbarFlowLayout.add(pbarConcentration);
jPanpbar.setLayout(new GridLayout(2,1,0,0));
jPanpbar.add(personalBest5);
jPanpbar.add(jPanpbarFlowLayout);
ParameterPan.add(zeitlbl2, BorderLayout.NORTH);
ParameterPan2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
ParameterPan2.add(jbtStart);
ParameterPan3.setLayout(new FlowLayout(FlowLayout.LEFT, 50, 10));
ParameterPan3.add(zeitlbl);
ParameterPan4.setLayout(new BorderLayout(5, 5));
ParameterPan4.add(ParameterPan2, BorderLayout.WEST);
ParameterPan4.add(ParameterPan3, BorderLayout.EAST);
ParameterPan.add(ParameterPan4,BorderLayout.SOUTH);
ParameterPan.setBorder(BorderFactory.createRaisedBevelBorder() );
ParameterPan2.setBackground(tfieldbgc);
ParameterPan3.setBackground(tfieldbgc);
ParameterPan4.setBackground(tfieldbgc);
ParameterPan.setBackground(tfieldbgc);
mainPan.setLayout(new BorderLayout(0,0));
jPanpersonalBest.setLayout(new GridLayout(6,1,0,0));
personalBest1.setOpaque(true);
personalBest2.setOpaque(true);
personalBest1.setText("Your personal record:");
personalBest2.setText(btimeaktintern + " Sec");
jPanpersonalBest.add(personalBest3);
jPanpersonalBest.add(personalBest4);
jPanpersonalBest.add(personalBest1);
jPanpersonalBest.add(personalBest2);
jPan2.setLayout(new BorderLayout(0,0));
jPan2.add(jPanpersonalBest, BorderLayout.CENTER);
mainPan.add(jPan2, BorderLayout.CENTER);
mainPan.add(ParameterPan, BorderLayout.SOUTH);
add(mainPan);
}