package Tauglichkeitstester;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import Einschaetzungstest.ZeichenPanelGUIEinschaetzung;
import Reaktionstest.ZeichenPanelGUIReaktion;
import Konzentrationstest.ZeichenPanelGUIKonzentration;
public class ControlPanel extends JFrame implements ActionListener {
private Button prog1 = null;
private Button prog2 = null;
private Button prog3 = null;
private Button prog4 = null;
private Button exit = null;
public ControlPanel(String title) {
super (title);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Panel cp = new Panel(null);
add(cp);
setLayout(null);
cp.setBackground(Color.yellow);
//Anfang Komponente
prog1 = new Button("Einschätzungstester");
prog1.setBackground(Color.RED);
prog1.setForeground(Color.black);
prog1.setFont(new Font("MS Sant Serif", 1, 30));
prog1.setBounds(152, 80, 473, 81);
prog2 = new Button("Reaktionstester");
prog2.setBackground(Color.blue);
prog2.setForeground(Color.black);
prog2.setFont(new Font("MS Sant Serif", 1, 30));
prog2.setBounds(152, 224, 473, 81);
prog3 = new Button("Konzentrationstester");
prog3.setBackground(Color.orange);
prog3.setForeground(Color.black);
prog3.setFont(new Font("MS Sant Serif", 1, 30));
prog3.setBounds(152, 376, 473, 81);
exit = new Button ( "EXIT");
exit.setBackground(Color.PINK);
exit.setForeground(Color.black);
exit.setFont(new Font("MS Sant Serif", 1, 12));
exit.setBounds(600,500,150,40);
add(prog1);
add(prog2);
add(prog3);
add (exit);
prog1.addActionListener(this);
prog2.addActionListener(this);
prog3.addActionListener(this);
exit.addActionListener(this);
setVisible(true);
}
//Ende Komponente
// public void ControlPanelSichtbar (){
// this.setVisible(true);
// }
public static void main(String[] args) {
new ControlPanel("Tauglichkeitstester");
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == prog1) {
ZeichenPanelGUIEinschaetzung.main(null);// Starter Klasse des 1. Programms
this.setVisible(false);
}
else if (evt.getSource() == prog2) {
ZeichenPanelGUIReaktion.main(null); // Starter Klasse des 2. Programms
this.setVisible(false);
}
else if (evt.getSource() == prog3) {
ZeichenPanelGUIKonzentration.main(null); // Starter Klasse des 3. Programms
this.setVisible(false);
}
else if (evt.getSource() == exit) {
System.exit(0);
}
}
}
package Konzentrationstest;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import javax.swing.*;
public class ZeichenPanel extends JPanel
{
private TauglichkeitsTest tTest;
private Runnable neuzeichnenRun;
private Thread dieserThread;
public ZeichenPanel(int i, int j)
{
setPreferredSize(new Dimension(i, j));
setBorder(BorderFactory.createLineBorder(Color.black, 10));
setOpaque(true);
setBackground(Color.white);
neuzeichnenRun = new Runnable() {
public void run()
{
neuzeichnen();
}
};
}
public void setTauglichkeitsTest(TauglichkeitsTest tauglichkeitstest)
{
tTest = tauglichkeitstest;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(tTest != null)
tTest.zeigeTestFigur(g);
}
public void start()
{
dieserThread = new Thread(neuzeichnenRun);
dieserThread.start();
}
public void stop()
{
if(dieserThread != null)
{
dieserThread.interrupt();
dieserThread = null;
}
}
private void neuzeichnen()
{
for(Thread thread = Thread.currentThread(); thread == dieserThread;)
{
try
{
SwingUtilities.invokeAndWait(dieserThread);
}
catch(InterruptedException interruptedexception) { }
catch(InvocationTargetException invocationtargetexception) { }
if(dieserThread != null)
synchronized(dieserThread)
{
repaint();
}
}
}
}
Hobbit_Im_Blutrausch hat gesagt.:Ich fasse mal eben zusammen, du hast jetzt folgende Klassen gepostet:
1x ControlPanel
1x KonzentrationsTest
1x StoppUhrGUI
1x StoppUhr
1x TastaturTest
1x Tauglichkeitstest
4x ZeichenPanel
3x ZeichenPanelGUIKonzentration
Was ich noch brauche ist:
1x ZiffernFeld
1x ZeichenPanelGUIEinschaetzung
1x ZeichenPanelGUIReaktion
evtl. kommt da auch noch was dazu, jenachdem was die noch benötigten Klassen wiederrum für Klassen benötigen.
Azrahel NA hat gesagt.:Ich hätt gern noch
1 x ZiffernFeld
2.4 x StoppUhr
0.223 x ControlPanel
package Reaktionstest;
import Tauglichkeitstester.ControlPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ZeichenPanelGUIReaktion extends JFrame {
public Font font;
public Color farbe;
// Anfang Variablen
private ZeichenPanel zeichenFlaeche = new ZeichenPanel(200,200);
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jbutton4 = new JButton();
private JButton jbutton5 = new JButton();
protected TauglichkeitsTest tTest = new ReaktionsTest(350, 240);;
//private JTextField jTextField1 = new JTextField();
private JScrollPane jScrollPanejTextArea1 = new JScrollPane();
private JTextArea jTextArea1 = new JTextArea("");
private JLabel jlb1 = new JLabel();
private JLabel jlb2 = new JLabel();
// Ende Variablen
public ZeichenPanelGUIReaktion (String title) {
// Frame-Initialisierung
super (title);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
zeichenFlaeche.setBounds(225, 80, 350, 240);
cp.add(zeichenFlaeche);
zeichenFlaeche.setTauglichkeitsTest(tTest);
jButton1.setBounds(30, 80, 130, 40);
jButton1.setText("Start");
jButton1.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton1.setBackground(Color.lightGray);
jButton1.setForeground(Color.black);
jButton1.setFont(new Font ("MS Sant Serif" , 1, 14));
cp.add(jButton1);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBounds(30, 180, 130, 40);
jButton2.setText("Stop");
jButton2.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton2.setBackground(Color.lightGray);
jButton2.setForeground(Color.black);
jButton2.setFont(new Font ("MS Sant Serif" , 1, 14));
cp.add(jButton2);
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBounds(30, 280, 130, 40);
jButton3.setText("Neu");
jButton3.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton3.setBackground(Color.lightGray);
jButton3.setForeground(Color.black);
jButton3.setFont(new Font ("MS Sant Serif" , 1, 14));
cp.add(jButton3);
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jlb1.setBounds(620, 163, 150, 75);
jlb1.setText("Reaktionszeit");
jlb1.setForeground(Color.red);
jlb1.setBorder(BorderFactory.createLineBorder(Color.black, 5));
jlb1.setFont(new Font("MS Sant Serif",1, 20));
jlb1.setHorizontalAlignment(SwingConstants.CENTER);
jlb1.setHorizontalTextPosition(SwingConstants.CENTER);
jlb1.setBackground(Color.white);
cp.add(jlb1);
//jTextField1.setBounds(630, 163, 120, 75);
//jTextField1.setText("Reaktionszeit");
//font = new Font ("Times New Roman", Font.BOLD,38);
//cp.add(jTextField1);
// public void setEditable(boolean allowed)
// public boolean isEditable()
// public void setEchoCharacter(char c)
// public char getEchoChar()
//
jScrollPanejTextArea1.setBounds(225, 400, 350, 100);
jTextArea1.setText("(String)");
jTextArea1.setFont(new Font("MS Sans Serif", 1, 11));
jTextArea1.setBackground(Color.LIGHT_GRAY);
jTextArea1.setForeground(Color.black);
jScrollPanejTextArea1.setViewportView(jTextArea1);
jTextArea1.setText(tTest.zeigeHilfe());
jTextArea1.setEditable(false);
cp.add(jScrollPanejTextArea1);
jbutton4.setBounds(625, 80, 130, 40);
jbutton4.setText("Hauptmenü");
jbutton4.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jbutton4.setBackground(Color.lightGray);
jbutton4.setForeground(Color.black);
jbutton4.setFont(new Font ("MS Sant Serif" , 1, 14));
cp.add(jbutton4);
jbutton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton4ActionPerformed(evt);
}
});
jbutton5.setBounds(625, 280, 130, 40);
jbutton5.setText("Highscore");
jbutton5.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jbutton5.setBackground(Color.lightGray);
jbutton5.setForeground(Color.black);
jbutton5.setFont(new Font ("MS Sant Serif" , 1, 14));
cp.add(jbutton5);
jbutton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton5ActionPerformed(evt);
}
});
jlb2.setBounds(225, 20, 350, 50);
jlb2.setText("Reaktionstester");
jlb2.setHorizontalAlignment(SwingConstants.CENTER);
jlb2.setHorizontalTextPosition(SwingConstants.CENTER);
jlb2.setFont(new Font("MS Sans Serif", 1, 24));
cp.add(jlb2);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void paint(Graphics g)
{
super.paintComponents(g);
}
//start
public void jButton1ActionPerformed(ActionEvent evt) {
jButton1.setEnabled(false);
if(tTest instanceof ReaktionsTest){
jButton1.setEnabled(false);
jButton2.setEnabled(true);
jButton3.setEnabled(false);
}
zeichenFlaeche.start();
tTest.starten();
}
//stop
public void jButton2ActionPerformed(ActionEvent evt) {
tTest.stoppen();
zeichenFlaeche.stop();
//jTextField1.setText(tTest.holeErgebnis());
jlb1.setText(tTest.holeErgebnis());
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(true);
}
//neu
public void jButton3ActionPerformed(ActionEvent evt) {
if(tTest instanceof ReaktionsTest){
tTest = new ReaktionsTest(350, 240);
}
reset(tTest);
zeichenFlaeche.repaint();
}
//Hauptmenü
public void jbutton4ActionPerformed(ActionEvent evt){
this.setVisible(false);
ControlPanel.main(null);
}
private void reset(TauglichkeitsTest tauglichkeitstest)
{
jButton1.setEnabled(true);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
zeichenFlaeche.setTauglichkeitsTest(tauglichkeitstest);
jTextArea1.setText(tauglichkeitstest.zeigeHilfe());
//jTextField1.setText(" ");
jlb1.setText("Reaktionszeit ");
}
// public void jbutton4ActionPerformed(ActionEvent evt) {
//
// }
public void jbutton5ActionPerformed(ActionEvent evt) {
}
// Ende Ereignisprozeduren
public static void main (String[] args) {
new ZeichenPanelGUIReaktion("Reakionstester");
}
}
package Konzentrationstest;
import Tauglichkeitstester.ControlPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ZeichenPanelGUIKonzentration extends JFrame {
// Anfang Variablen
private ZeichenPanel zeichenFlaeche = new ZeichenPanel(200,200);
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
protected TauglichkeitsTest tTest = new KonzentrationsTest(350, 240);;
//private JTextField jTextField1 = new JTextField();
private JScrollPane jScrollPanejTextArea1 = new JScrollPane();
private JTextArea jTextArea1 = new JTextArea("");
private JButton jbutton4 = new JButton();
private JButton jbutton5 = new JButton();
private JLabel jlb1 = new JLabel();
private JLabel jlb2 = new JLabel();
// Ende Variablen
//Eine private Klasse
private class TauglichkeitsTestKeyAdapter extends KeyAdapter
{
public void keyTyped(KeyEvent keyevent)
{
if(tTest instanceof KonzentrationsTest)
{
char c = keyevent.getKeyChar();
if(((KonzentrationsTest)tTest).istAktiv() && c == ((KonzentrationsTest)tTest).gibZiffer())
{
tTest.stoppen();
zeichenFlaeche.stop();
//jTextField1.setText(tTest.holeErgebnis());
jlb1.setText(tTest.holeErgebnis());
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(true);
}
}
}
private TauglichkeitsTestKeyAdapter()
{
}
}
public ZeichenPanelGUIKonzentration (String title) {
// Frame-Initialisierung
super (title);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addKeyListener(new TauglichkeitsTestKeyAdapter());
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent mouseevent)
{
requestFocus();
}
});
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
zeichenFlaeche.setBounds(225, 80, 350, 240);
cp.add(zeichenFlaeche);
zeichenFlaeche.setTauglichkeitsTest(tTest);
jButton1.setBounds(30, 80, 130, 40);
jButton1.setText("Start");
jButton1.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton1.setFont(new Font("MS Sant Serif", 1, 14));
cp.add(jButton1);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBounds(30, 180, 130, 40);
jButton2.setText("Stop");
jButton2.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton2.setFont(new Font("MS Sant Serif", 1, 14));
cp.add(jButton2);
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBounds(30, 280, 130, 40);
jButton3.setText("Neu");
jButton3.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton3.setFont(new Font("MS Sant Serif", 1, 14));
cp.add(jButton3);
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jlb1.setBounds(620, 163, 150, 75);
jlb1.setText("Reaktionszeit");
jlb1.setFont(new Font("MS Sans Serif", 1, 20));
jlb1.setForeground(Color.red);
jlb1.setBorder(BorderFactory.createLineBorder(Color.black, 5));
jlb1.setHorizontalAlignment(SwingConstants.CENTER);
jlb1.setHorizontalTextPosition(SwingConstants.CENTER);
cp.add(jlb1);
//jTextField1.setBounds(0, 40, 281, 24);
//jTextField1.setText("Reaktionszeit");
//cp.add(jTextField1);
jScrollPanejTextArea1.setBounds(225, 400, 350, 100);
jTextArea1.setText("(Strings)");
jTextArea1.setForeground(Color.black);
jTextArea1.setFont(new Font("MS Sans Serif", 1, 11));
jTextArea1.setBackground(Color.LIGHT_GRAY);
jTextArea1.setEditable(false);
jScrollPanejTextArea1.setViewportView(jTextArea1);
jTextArea1.setText(tTest.zeigeHilfe());
cp.add(jScrollPanejTextArea1);
jbutton4.setBounds(625, 80, 130, 40);
jbutton4.setText("Hauptmenü");
jbutton4.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jbutton4.setHorizontalAlignment(SwingConstants.CENTER);
jbutton4.setHorizontalTextPosition(SwingConstants.CENTER);
jbutton4.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jbutton4);
jbutton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton4ActionPerformed(evt); } });
jbutton5.setBounds(625, 280, 130, 40);
jbutton5.setText("Highscore");
jbutton5.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jbutton5.setHorizontalAlignment(SwingConstants.CENTER);
jbutton5.setHorizontalTextPosition(SwingConstants.CENTER);
jbutton5.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jbutton5);
jbutton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton5ActionPerformed(evt); } });
jlb2.setBounds(225, 20, 350, 50);
jlb2.setText("Konzentrationstest");
jlb2.setHorizontalAlignment(SwingConstants.CENTER);
jlb2.setHorizontalTextPosition(SwingConstants.CENTER);
jlb2.setFont(new Font("MS Sans Serif", 1, 24));
cp.add(jlb2);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void paint(Graphics g)
{
super.paintComponents(g);
}
//start
public void jButton1ActionPerformed(ActionEvent evt) {
jButton1.setEnabled(false);
if(tTest instanceof KonzentrationsTest){
jButton1.setEnabled(false);
jButton2.setEnabled(true);
jButton3.setEnabled(false);
}
zeichenFlaeche.start();
tTest.starten();
}
//stop
public void jButton2ActionPerformed(ActionEvent evt) {
tTest.stoppen();
zeichenFlaeche.stop();
//jTextField1.setText(tTest.holeErgebnis());
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(true);
//jTextField1.setText("***Abbruch***");
}
//neu
public void jButton3ActionPerformed(ActionEvent evt) {
if(tTest instanceof KonzentrationsTest){
tTest = new KonzentrationsTest(200, 200);
}
reset(tTest);
zeichenFlaeche.repaint();
}
//Hauptmenü
public void jbutton4ActionPerformed(ActionEvent evt){
this.setVisible(false);
ControlPanel.main(null);
}
private void reset(TauglichkeitsTest tauglichkeitstest)
{
jButton1.setEnabled(true);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
zeichenFlaeche.setTauglichkeitsTest(tauglichkeitstest);
jTextArea1.setText(tauglichkeitstest.zeigeHilfe());
jlb1.setText("Reaktionszeit ");
//jTextField1.setText(" ");
}
public boolean isFocusablejButton1()
{
jButton1.requestFocus(false);
return false;
}
// public void jbutton4ActionPerformed(ActionEvent evt) {
//
// }
public void jbutton5ActionPerformed(ActionEvent evt) {
}
// Ende Ereignisprozeduren
public static void main (String[] args) {
new ZeichenPanelGUIKonzentration("Tauglichkeitstest");
}
}
package Tauglichkeitstester;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import Einschaetzungstest.ZeichenPanelGUIEinschaetzung;
import Reaktionstest.ZeichenPanelGUIReaktion;
import Konzentrationstest.ZeichenPanelGUIKonzentration;
public class ControlPanel extends JFrame implements ActionListener {
private Button prog1 = null;
private Button prog2 = null;
private Button prog3 = null;
private Button prog4 = null;
private Button exit = null;
public ControlPanel(String title) {
super (title);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Panel cp = new Panel(null);
add(cp);
setLayout(null);
//cp.setBackground(Color.yellow);
//Anfang Komponente
prog1 = new Button("Einschätzungstester");
prog1.setBackground(Color.RED);
prog1.setForeground(Color.black);
prog1.setFont(new Font("MS Sant Serif", 1, 30));
prog1.setBounds(152, 80, 473, 81);
prog2 = new Button("Reaktionstester");
prog2.setBackground(Color.blue);
prog2.setForeground(Color.black);
prog2.setFont(new Font("MS Sant Serif", 1, 30));
prog2.setBounds(152, 224, 473, 81);
prog3 = new Button("Konzentrationstester");
prog3.setBackground(Color.orange);
prog3.setForeground(Color.black);
prog3.setFont(new Font("MS Sant Serif", 1, 30));
prog3.setBounds(152, 376, 473, 81);
exit = new Button ( "EXIT");
exit.setBackground(Color.PINK);
exit.setForeground(Color.black);
exit.setFont(new Font("MS Sant Serif", 1, 12));
exit.setBounds(600,500,150,40);
add(prog1);
add(prog2);
add(prog3);
add (exit);
prog1.addActionListener(this);
prog2.addActionListener(this);
prog3.addActionListener(this);
exit.addActionListener(this);
setVisible(true);
}
//Ende Komponente
// public void ControlPanelSichtbar (){
// this.setVisible(true);
// }
public static void main(String[] args) {
new ControlPanel("Tauglichkeitstester");
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == prog1) {
ZeichenPanelGUIEinschaetzung.main(null);// Starter Klasse des 1. Programms
this.setVisible(false);
}
else if (evt.getSource() == prog2) {
ZeichenPanelGUIReaktion.main(null); // Starter Klasse des 2. Programms
this.setVisible(false);
}
else if (evt.getSource() == prog3) {
ZeichenPanelGUIKonzentration.main(null); // Starter Klasse des 3. Programms
this.setVisible(false);
}
else if (evt.getSource() == exit) {
System.exit(0);
}
}
}
package Einschaetzungstest;
import Tauglichkeitstester.ControlPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ZeichenPanelGUIEinschaetzung extends JFrame {
// Anfang Variablen
private ZeichenPanel zeichenFlaeche = new ZeichenPanel(200,200);
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JButton jButton5 = new JButton();
private JLabel jlb1 = new JLabel();
protected TauglichkeitsTest tTest = new EinschaetzungsTest(350, 240);;
//private JTextField jTextField1 = new JTextField();
private JScrollPane jScrollPanejTextArea1 = new JScrollPane();
private JTextArea jTextArea1 = new JTextArea("");
private JLabel jlb2 = new JLabel();
// Ende Variablen
public ZeichenPanelGUIEinschaetzung (String title) {
// Frame-Initialisierung
super (title);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
zeichenFlaeche.setBounds(225, 80, 350, 240);
cp.add(zeichenFlaeche);
zeichenFlaeche.setTauglichkeitsTest(tTest);
jButton1.setBounds(30, 80, 130, 40);
jButton1.setText("Start");
jButton1.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton1.setBackground(Color.lightGray);
jButton1.setForeground(Color.black);
jButton1.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jButton1);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBounds(30, 180, 130, 40);
jButton2.setText("Stop");
jButton2.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton2.setBackground(Color.lightGray);
jButton2.setForeground(Color.black);
jButton2.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jButton2);
jButton2.setEnabled(false);
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBounds( 30, 280, 130, 40);
jButton3.setText("Neu");
jButton3.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton3.setBackground(Color.lightGray);
jButton3.setForeground(Color.black);
jButton3.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jButton3);
jButton3.setEnabled(false);
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
//jTextField1.setBounds(630, 163, 120, 75);
//jTextField1.setText("Reaktionszeit");
//cp.add(jTextField1);
jlb1.setBounds(620, 163, 150, 75);
jlb1.setText("Abweichung");
jlb1.setFont(new Font("MS Sant Serif",1, 22));
jlb1.setForeground(Color.red);
jlb1.setBackground(Color.white);
jlb1.setBorder(BorderFactory.createLineBorder(Color.black, 5));
jlb1.setOpaque(true);
jlb1.setHorizontalAlignment(SwingConstants.CENTER);
jlb1.setHorizontalTextPosition(SwingConstants.CENTER);
cp.add(jlb1);
jScrollPanejTextArea1.setBounds(225, 400, 350, 100);
jTextArea1.setText("(Strings)");
jTextArea1.setFont(new Font("MS Sans Serif", 1, 11));
jTextArea1.setBackground(Color.LIGHT_GRAY);
jTextArea1.setForeground(Color.black);
jScrollPanejTextArea1.setViewportView(jTextArea1);
jTextArea1.setText(tTest.zeigeHilfe());
jTextArea1.setEditable(false);
cp.add(jScrollPanejTextArea1);
jButton4.setBounds(625, 80, 130, 40);
jButton4.setText("Hauptmenü");
jButton4.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton4.setBackground(Color.lightGray);
jButton4.setForeground(Color.black);
jButton4.setHorizontalAlignment(SwingConstants.CENTER);
jButton4.setHorizontalTextPosition(SwingConstants.CENTER);
jButton4.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jButton4);
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setBounds(625, 280, 130, 40);
jButton5.setText("Highscore");
jButton5.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
jButton5.setBackground(Color.lightGray);
jButton5.setForeground(Color.black);
jButton5.setHorizontalAlignment(SwingConstants.CENTER);
jButton5.setHorizontalTextPosition(SwingConstants.CENTER);
jButton5.setFont(new Font("MS Sans Serif", 1, 14));
cp.add(jButton5);
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton5ActionPerformed(evt); } });
jlb2.setBounds(225, 20, 350, 50);
jlb2.setText("Einschätzungstest");
jlb2.setBackground(Color.white);
jlb2.setOpaque(false);
jlb2.setHorizontalAlignment(SwingConstants.CENTER);
jlb2.setHorizontalTextPosition(SwingConstants.CENTER);
jlb2.setFont(new Font("MS Sans Serif", 1, 24));
jlb2.setForeground(Color.black);
cp.add(jlb2);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void paint(Graphics g)
{
super.paintComponents(g);
}
//start
public void jButton1ActionPerformed(ActionEvent evt) {
jButton1.setEnabled(false);
if(tTest instanceof EinschaetzungsTest){
jButton1.setEnabled(false);
jButton2.setEnabled(true);
jButton3.setEnabled(false);
}
zeichenFlaeche.start();
tTest.starten();
this.setSize(800,600);
}
//stop
public void jButton2ActionPerformed(ActionEvent evt) {
tTest.stoppen();
zeichenFlaeche.stop();
//jTextField1.setText(tTest.holeErgebnis());
jlb1.setText(tTest.holeErgebnis());
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(true);
this.setSize(800,601);
}
//neu
public void jButton3ActionPerformed(ActionEvent evt) {
if(tTest instanceof EinschaetzungsTest){
tTest = new EinschaetzungsTest(200, 200);
}
reset(tTest);
zeichenFlaeche.repaint();
}
//Zurück zum Hauptmenü
public void jButton4ActionPerformed(ActionEvent evt){
this.setVisible(false);
ControlPanel.main(null);
}
private void reset(TauglichkeitsTest tauglichkeitstest)
{
jButton1.setEnabled(true);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
zeichenFlaeche.setTauglichkeitsTest(tauglichkeitstest);
jTextArea1.setText(tauglichkeitstest.zeigeHilfe());
//jTextField1.setText(" ");
jlb1.setText(" ");
}
public void jButton5ActionPerformed(ActionEvent evt) {
}
// Ende Ereignisprozeduren
public static void main (String[] args) {
new ZeichenPanelGUIEinschaetzung("Tauglichkeitstester");
}
}
package Konzentrationstest;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import javax.swing.*;
public class ZeichenPanel extends JPanel
{
private TauglichkeitsTest tTest;
private Runnable neuzeichnenRun;
private Thread dieserThread;
public ZeichenPanel(int i, int j)
{
setPreferredSize(new Dimension(i, j));
setBorder(BorderFactory.createLineBorder(Color.black, 10));
setOpaque(true);
setBackground(Color.white);
neuzeichnenRun = new Runnable() {
public void run()
{
neuzeichnen();
}
};
}
public void setTauglichkeitsTest(TauglichkeitsTest tauglichkeitstest)
{
tTest = tauglichkeitstest;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(tTest != null)
tTest.zeigeTestFigur(g);
}
public void start()
{
dieserThread = new Thread(neuzeichnenRun);
dieserThread.start();
}
public void stop()
{
if(dieserThread != null)
{
dieserThread.interrupt();
dieserThread = null;
}
}
private void neuzeichnen()
{
for(Thread thread = Thread.currentThread(); thread == dieserThread;)
{
try
{
SwingUtilities.invokeAndWait(dieserThread);
}
catch(InterruptedException interruptedexception) { }
catch(InvocationTargetException invocationtargetexception) { }
if(dieserThread != null)
synchronized(dieserThread)
{
repaint();
}
}
}
}
ET5F1 hat gesagt.:was du mit ziffern Feld meinst.
ET5F1 hat gesagt.:Da steht Ziffern feld
Lösung
ET5F1 hat gesagt.:Wir öffnen alle Progamme und nur bei einem steht Ziffern Feld und das ist falsch
ET5F1 hat gesagt.:Ich habe dir das Controll Pannel
ET5F1 hat gesagt.:und da kannst du das Programm ausprobieren
ET5F1 hat gesagt.:aber du willst dies und das haben
ET5F1 hat gesagt.:Ich glaube du hast die Funktion garnicht kappiert.
ET5F1 hat gesagt.:aber ich glaube du könntest das Problem mit dem Focus auch nicht beheben,weil Du ja noch in der Ausbildung bist.
package Einschaetzungstest;
import java.awt.Color;
public class Ballon extends Kreis
{
private Runnable wachseRadiusRun;
private Thread thread;
public Ballon(int i, int j, Color color)
{
super(i, j, 0, color); // Kreis mit Radius 0 wird erzeugt
wachseRadiusRun = new Runnable()
{
public void run()
{
wachseRadius();
}
};
}
public void start()
{
thread = new Thread(wachseRadiusRun);
thread.start();
}
private void wachseRadius()
{
for(Thread thread1 = Thread.currentThread(); thread1 == thread;)
{
try
{
Thread.sleep(50L); //Schnelligkeit des Wachsens
}
catch(InterruptedException interruptedexception)
{
return;
}
synchronized(thread1)
{
if(radius < 120) //maximale Ballondurchmesser
radius++;
}
}
}
public void stop()
{
if(thread != null)
{
thread.interrupt();
thread = null;
}
}
}
package Einschaetzungstest;
import java.awt.*;
public class BallonFeld
{
protected Quadrat quadrat;
protected Ballon ballon;
protected KQuadrat kQuadrat;
private Figur figur;
private int xMitte;
private int yMitte;
private Runnable warteRun;
private Thread dieserThread;
public BallonFeld(int i, int j, int k)
{
xMitte = i;
yMitte = j;
int l = k / 10;
int i1 = k / 4;
int j1 = i1 + (int)(Math.random() * (double)(k - i1 - 2 * l));
int k1 = (int)((1.0D - 2D * Math.random()) * (double)(i - j1 / 2 - l));
int l1 = (int)((1.0D - 2D * Math.random()) * (double)(j - j1 / 2 - l));
quadrat = new Quadrat(i - k1, j - l1, j1, Color.GREEN);
ballon = new Ballon(i + k1, j + l1, Color.RED);
kQuadrat = new KQuadrat(i, j, j1, quadrat.gibFarbe(), ballon);
figur = null;
warteRun = new Runnable() {
public void run()
{
warte(2000); //2000bei anderen Werten keine Veränderung zu sehen
}
};
}
public void starten()
{
figur = quadrat;
dieserThread = new Thread(warteRun);
dieserThread.start();
}
private void warte(int i)
{
for(Thread thread = Thread.currentThread(); dieserThread == thread;)
{
try
{
Thread.sleep(1000L);//war 2000 -Quadrat wird angezeigt
}
catch(InterruptedException interruptedexception)
{
return;
}
if(dieserThread != null)
{
dieserThread = null;
ballon.start();
figur = ballon;
}
}
}
public void stoppen()
{
if(dieserThread != null)
{
dieserThread.interrupt();
dieserThread = null;
}
ballon.stop();
ballon.setzeMittelpunkt(xMitte, yMitte);
figur = kQuadrat;
}
public int ergebnis()
{
return (int)Math.round((((double)quadrat.gibSeite() - 2D * (double)ballon.gibRadius()) * 100D) / (double)quadrat.gibSeite());
}
public void darstellen(Graphics g)
{
if(figur != null)
figur.darstellen(g);
}
}
package Einschaetzungstest;
import java.awt.Graphics;
public class EinschaetzungsTest extends TauglichkeitsTest
{
protected BallonFeld einBallonFeld;
public EinschaetzungsTest(int i, int j)
{
super(i, j);
einBallonFeld = new BallonFeld(xMitte, yMitte, (Math.min(i, j) * 9) / 10);
}
public void tueNachStart()
{
einBallonFeld.starten();
}
public void stoppen()
{
super.stoppen();
einBallonFeld.stoppen();
}
public String holeErgebnis()
{
return " " + Integer.toString(Math.abs(einBallonFeld.ergebnis())) + "% " + (einBallonFeld.ergebnis() >= 0 ? einBallonFeld.ergebnis() <= 0 ? "" : "zu klein" : "zu groß");
}
public String zeigeHilfe()
{
return "Klicken Sie auf 'Start'\nWarten Sie bis das gruene Quadrat erscheint.\nNach 2 Sekunden beginnt ein roter Ballon zu wachsen.\nWenn Sie glauben,\ndass der Ballon gerade noch durch das gruene Quadrat passt,\nklicken Sie auf 'Stopp'.";
}
public void zeigeTestFigur(Graphics g)
{
einBallonFeld.darstellen(g);
}
}