import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; /** * * GUI zur Anzeige einer einzigen Frage des Quizspiels * * @version 1.0 from 15.11.2016 * @author Thomas Schaller */ public class FrageGUI extends JDialog { // Anfang Attribute private JLabel jLabel1 = new JLabel(); private JLabel jLFrage = new JLabel(); private JButton jB_A1 = new JButton(); private JButton jB_A2 = new JButton(); private JButton jB_A3 = new JButton(); private JButton jB_A4 = new JButton(); private JLabel jLName = new JLabel(); private JPanel jPanel1 = new JPanel(null, true); private int antwort = -1; // Ende Attribute public FrageGUI (JFrame owner, String frage, String a1, String a2, String a3, String a4, int sp) { super (owner, true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); int frameWidth = 657; int frameHeight = 447; 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 jLabel1.setBounds(8, 8, 78, 81); jLabel1.setText("
Frage:
"); jLabel1.setFont(new Font("Dialog", Font.BOLD, 20)); jLabel1.setVerticalTextPosition(JLabel.TOP); cp.add(jLabel1); jLFrage.setBounds(96, 0, 534, 97); jLFrage.setText(""+frage+""); jLFrage.setFont(new Font("Dialog", Font.BOLD, 20)); jLFrage.setVerticalTextPosition(SwingConstants.TOP); cp.add(jLFrage); jB_A1.setBounds(8, 96, 329, 121); jB_A1.setText(""+a1+"
"); jB_A1.setMargin(new Insets(2, 2, 2, 2)); jB_A1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jB_A1_ActionPerformed(evt); } }); jB_A1.setFont(new Font("Dialog", Font.BOLD, 16)); jB_A1.setBackground(new Color(0xB8CFE5)); jB_A1.setHorizontalTextPosition(SwingConstants.CENTER); cp.add(jB_A1); jB_A2.setBounds(352, 96, 281, 121); jB_A2.setText(""+a2+"
"); jB_A2.setMargin(new Insets(2, 2, 2, 2)); jB_A2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jB_A2_ActionPerformed(evt); } }); jB_A2.setFont(new Font("Dialog", Font.BOLD, 16)); jB_A2.setBackground(new Color(0xB8CFE5)); cp.add(jB_A2); jB_A3.setBounds(8, 224, 329, 137); jB_A3.setText(""+a3+"
"); jB_A3.setMargin(new Insets(2, 2, 2, 2)); jB_A3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jB_A3_ActionPerformed(evt); } }); jB_A3.setFont(new Font("Dialog", Font.BOLD, 16)); jB_A3.setBackground(new Color(0xB8CFE5)); cp.add(jB_A3); jB_A4.setBounds(352, 224, 281, 137); jB_A4.setText(""+a4+"
"); jB_A4.setMargin(new Insets(2, 2, 2, 2)); jB_A4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jB_A4_ActionPerformed(evt); } }); jB_A4.setFont(new Font("Dialog", Font.BOLD, 16)); jB_A4.setBackground(new Color(0xB8CFE5)); cp.add(jB_A4); jLName.setBounds(8, 360, 624, 45); jLName.setText("Spieler "+sp+" entscheide dich!"); jLName.setFont(new Font("Dialog", Font.BOLD, 24)); cp.add(jLName); setUndecorated(true); jPanel1.setBounds(0, 0, 641, 409); jPanel1.setOpaque(false); jPanel1.setBorder(new javax.swing.border.LineBorder(Color.BLACK, 2)); cp.add(jPanel1); // Ende Komponenten setResizable(false); } // Anfang Methoden public void jB_A1_ActionPerformed(ActionEvent evt) { antwort = 1; jB_A1.setEnabled(false); this.setVisible(false); } // end of jB_A1_ActionPerformed public void jB_A2_ActionPerformed(ActionEvent evt) { antwort = 2; jB_A2.setEnabled(false); this.setVisible(false); } // end of jB_A2_ActionPerformed public void jB_A3_ActionPerformed(ActionEvent evt) { antwort = 3; jB_A3.setEnabled(false); this.setVisible(false); } // end of jB_A3_ActionPerformed public void jB_A4_ActionPerformed(ActionEvent evt) { antwort = 4; jB_A4.setEnabled(false); this.setVisible(false); } // end of jB_A4_ActionPerformed public int getAntwort() { return antwort; } public void setSpieler(int sp) { jLName.setText("Spieler "+sp+" entscheide dich!"); } // Ende Methoden }