Guten Abend!
Für meinen Informatikkurs soll ich einen Multiple Choice Test mit dem JavaEditor programmieren. Bisher komme ich auch ganz gut zurecht, leider kann ich nun nicht mehr sehen ob das Programm noch funktioniert da es zwar startet aber es sich nicht öffnet?
Bis ich angefangen habe diesen Code in die JButtons einzufügen hat auch noch das Starten geklappt:
Google gibt mir ebenfalls keine nutzbaren Antworten. Irgendwelche Ideen oder stelle ich mich schusselig an?
Freundliche Grüße,
Jennifer
Für meinen Informatikkurs soll ich einen Multiple Choice Test mit dem JavaEditor programmieren. Bisher komme ich auch ganz gut zurecht, leider kann ich nun nicht mehr sehen ob das Programm noch funktioniert da es zwar startet aber es sich nicht öffnet?
Bis ich angefangen habe diesen Code in die JButtons einzufügen hat auch noch das Starten geklappt:
Java:
if (Status1 == 1) {
jButton2.setBackground(Color.pink);
Status2 = 2;
} // end of if
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 25.03.2018
* @author
*/
public class MultipleChoice extends JFrame {
// Anfang Attribute
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JLabel TextFeld = new JLabel();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JButton bStarten = new JButton();
private JLabel lSpieler = new JLabel();
private JLabel lSpieler2 = new JLabel();
int Status1 = 0;
int Status2 = 0;
int Status3 = 0;
int Status4 = 0;
// Ende Attribute
public MultipleChoice() {
// Frame-Initialisierung
super();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 736;
int frameHeight = 602;
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);
setTitle("MultipleChoice");
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
jButton1.setBounds(48, 208, 289, 89);
jButton1.setText("");
jButton1.setMargin(new Insets(2, 2, 2, 2));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
jButton1.setBackground(new Color(0xFFC800));
cp.add(jButton1);
jButton2.setBounds(384, 208, 289, 89);
jButton2.setText("");
jButton2.setMargin(new Insets(2, 2, 2, 2));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2_ActionPerformed(evt);
}
});
jButton2.setBackground(new Color(0xFFC800));
cp.add(jButton2);
jButton3.setBounds(48, 336, 289, 89);
jButton3.setText("");
jButton3.setMargin(new Insets(2, 2, 2, 2));
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton3_ActionPerformed(evt);
}
});
jButton3.setBackground(new Color(0xFFC800));
cp.add(jButton3);
jButton4.setBounds(384, 336, 289, 89);
jButton4.setText("");
jButton4.setMargin(new Insets(2, 2, 2, 2));
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton4_ActionPerformed(evt);
}
});
jButton4.setBackground(new Color(0xFFC800));
cp.add(jButton4);
TextFeld.setBounds(40, 24, 643, 153);
TextFeld.setText("");
TextFeld.setBackground(Color.YELLOW);
TextFeld.setOpaque(true);
cp.add(TextFeld);
jLabel1.setBounds(280, 512, 59, 33);
jLabel1.setText("");
cp.add(jLabel1);
jLabel2.setBounds(384, 512, 59, 33);
jLabel2.setText("");
cp.add(jLabel2);
bStarten.setBounds(48, 496, 113, 41);
bStarten.setText("Starten");
bStarten.setMargin(new Insets(2, 2, 2, 2));
bStarten.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bStarten_ActionPerformed(evt);
}
});
bStarten.setBackground(new Color(0xC0C0C0));
cp.add(bStarten);
lSpieler.setBounds(264, 480, 83, 25);
lSpieler.setText("Spieler 1");
lSpieler.setBackground(Color.CYAN);
lSpieler.setOpaque(true);
lSpieler.setForeground(Color.BLACK);
lSpieler.setFont(new Font("Dialog", Font.BOLD, 12));
cp.add(lSpieler);
lSpieler2.setBounds(376, 480, 83, 25);
lSpieler2.setText("Spieler 2");
lSpieler2.setBackground(new Color(0xFFAFAF));
lSpieler2.setOpaque(true);
cp.add(lSpieler2);
cp.setBackground(Color.WHITE);
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton4.setEnabled(false);
// Ende Komponenten
} // end of public MultipleChoice
// Anfang Methoden
public static void main(String[] args) {
new MultipleChoice();
} // end of main
public void jButton1_ActionPerformed(ActionEvent evt) {
jButton1.setBackground(Color.cyan);
Status1 = 1;
if (Status2 == 1) {
jButton1.setBackground(Color.pink);
Status1 = 2;
} // end of if
if (Status3 == 1) {
jButton1.setBackground(Color.pink);
Status1 = 2;
} // end of if
if (Status4 == 1) {
jButton1.setBackground(Color.pink);
Status1 = 2;
} // end of if
} // end of jButton1_ActionPerformed
public void jButton2_ActionPerformed(ActionEvent evt) {
jButton2.setBackground(Color.cyan);
Status2 = 1;
if (Status1 == 1) {
jButton2.setBackground(Color.pink);
Status2 = 2;
} // end of if
if (Status3 == 1) {
jButton2.setBackground(Color.pink);
Status2 = 2;
} // end of if
if (Status4 == 1) {
jButton2.setBackground(Color.pink);
Status2 = 2;
} // end of if
} // end of jButton2_ActionPerformed
public void jButton3_ActionPerformed(ActionEvent evt) {
jButton3.setBackground(Color.cyan);
Status3 = 1;
if (Status2 == 1) {
jButton3.setBackground(Color.pink);
Status3 = 2;
} // end of if
if (Status1 == 1) {
jButton3.setBackground(Color.pink);
Status3 = 2;
} // end of if
if (Status4 == 1) {
jButton3.setBackground(Color.pink);
Status3 = 2;
} // end of if
} // end of jButton3_ActionPerformed
public void jButton4_ActionPerformed(ActionEvent evt) {
jButton4.setBackground(Color.cyan);
Status4 = 1;
if (Status1 == 1) {
jButton4.setBackground(Color.pink);
Status4 = 2;
} // end of if
if (Status2 == 1) {
jButton4.setBackground(Color.pink);
Status4 = 2;
} // end of if
if (Status3 == 1) {
jButton4.setBackground(Color.pink);
Status4 = 2;
} // end of if
} // end of jButton4_ActionPerformed
public void bStarten_ActionPerformed(ActionEvent evt) {
jButton1.setEnabled(true);
jButton2.setEnabled(true);
jButton3.setEnabled(true);
jButton4.setEnabled(true);
TextFeld.setText("1. Wie heißt der Hauptcharacter in Angry Birds?");
jButton1.setText("Peter");
jButton2.setText("Dino");
jButton3.setText("Red");
jButton4.setText("Angry");
} // end of bStarten_ActionPerformed
// Ende Methoden
} // end of class MultipleChoice
Google gibt mir ebenfalls keine nutzbaren Antworten. Irgendwelche Ideen oder stelle ich mich schusselig an?
Freundliche Grüße,
Jennifer