package quiz;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import more java.awt.event.ActionListener;
import javax.swing.*;
public class Quiz_Fenster extends JFrame implements ActionListener {
/**
* author: JaDaHB1, 30.11.2012
*/
//Bildschirmgr e becomes ausgelesen
dimension dim = tool kit GET default TARGET9_0_ kit () .getScreenSize ();
private JLabel frage2;
private JButton ant [] = new JButton [4];
questions ask;
JFrame w1;
frage_change CHANGEs;
Object [] option = {“OK ONES”};
l int ung;
JProgressBar b;
int correctly;
public Quiz_Fenster () {
//Fenster becomes erstellt
w1 = new JFrame ();
w1.setSize (400,300);
//Fenster becomes on the center of the screen gesetzt
w1.setLocation ((int) (dim.getWidth () - 400)/2,(int) (dim.getHeight () - 300) /2);
w1.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
w1.setVisible (true);
//Layout = ZERO is called we puts x, y fest
w1.setLayout (zero);
//Der first button, and to which ActionListener registered with it to button printing are reacted kann
ant [0] = new JButton (” - “);
ant [0] .setBounds (52,90,120,40);
ant [0] more.addActionListener (this);
//Button becomes on the Oberfl 臘 he hinzugef ・ t
w1.add (ant [0]);
[1] = new JButton ant (” - “);
ant [1] .setBounds (52,160,120,40);
ant [1] more.addActionListener (this);
w1.add (ant [1]);
[2] = new JButton ant (” - “);
ant [2] .setBounds (220,90,120,40);
ant [2] more.addActionListener (this);
w1.add (ant [2]);
[3] = new JButton ant (” - “);
ant [3] .setBounds (220,160,120,40);
ant [3].more addActionListener (this);
w1.add (ant [3]);
frage2 = new JLabel (“here the question” stands);
frage2.setBounds (52,15,250,40);
w1.add (frage2);
b = new JProgressBar (0,100);
b.setBounds (120,220,140,25);
b.setValue (0);
b.setStringPainted (true);
w1.add (b);
}
public static void Main (string [] args) {
new frage_change ();
}
public void actionPerformed (ActionEvent e) {
//e.getSource is called the causer of the click, L ung is the correct answer to the Frage
//Wenn button 1 correct
if (e.getSource () == ant [0]) {
if (l ung == 1) {
message (“correct”, “far ones so…”);
percent ();
frage_change.neueFrage ();
} else {
message (“wrong”, “not so…”);
}
}
//Wenn button 2 richtig
if (e.GET SOURCE () == ant [1]) {
if (l ung == 2) {
message (“correct”, “far ones so…”);
percent ();
frage_change.neueFrage ();
} else {
message (“wrong”, “not so…”);
}
}
//Wenn button 3 richtig
if (e.getSource () == ant [2]) {
if (l ung == 3) {
message (“correct”, “far ones so…”);
percent ();
frage_change.neueFrage ();
} else {
message (“wrong”, “not so…”);
}
}
//Wenn button 4 richtig
if (e.getSource () == ant [3]) {
if (l ung == 4) {
message (“correct”, “far ones so…”);
percent ();
frage_change.neueFrage ();
} else {
message (“wrong”, “not so…”);
}
}
}
//button text 舅 dern
public void CHANGE text button (button, string text int) {
ant [button-1] .setText (text);
}
//label text 舅 dern
public void CHANGE text label (string text) {
frage2.setText (text);
}
//converting into Prozent
public void calculation of percentage (int number, int entirely) {
b.setValue ((int) 100/gesamt*zahl);
}
//Nachricht ausgeben
public void message (string statement, string info) {
JOptionPane.showOptionDialog (zero, statement, info,
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
zero, option, option [0]);
}
//Wenn all questions answers wurden.
public void percent () {
if (correctly <= 7) {
correctly = 1;
calculation of percentage (correct, 8);
} else {
message (“super! ”, “cordial Gl ・ kwunsch:)”);
system exit (0);
}
}
}
đang được dịch, vui lòng đợi..