I am creating a small program. The program should consist of the following things:
First it opens a window with a picture and text. It also has a Button "Let's Go!" which opens a JOptionPane with some dialog and 4 different Buttons. (It's suposed to be a quiz, so a Question and 4 different answers) When you click the wrong answer it says something like "Wrong answer, try again" If you click the right answer it say: "Right answer, feel free to procede" or something like that and the next Question opens up.
So far so good. I am pretty new to Java and this is my first "big" programm and I already got a bit stuck. The Problem I am currently facing is: How can I place a JButton in my JFrame with the Picture and the Text? I created one bit it is either not displayed or below the Picture. Here is my code so far:
import java.awt.*;
import javax.swing.*;
public class HBA extends JFrame {
public HBA() {
setSize(1100, 720);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout (new FlowLayout(FlowLayout.CENTER));
Icon icon = new ImageIcon("HappyBirthday.jpg");
JLabel label1 = new JLabel("Happy Birthday Anna!", JLabel.CENTER);
JLabel label2 = new JLabel("Und viel Erfolg mit diesem Geschenk! ;)", JLabel.CENTER);
JLabel label3 = new JLabel(icon);
JButton OK = new JButton("Let's Go!");
Font schrift = new Font("ComicSans", Font.BOLD, 24);
label1.setFont(schrift);
label2.setFont(schrift);
label1.setForeground(Color.black);
label2.setForeground(Color.black);
getContentPane().add(label1);
getContentPane().add(label2);
getContentPane().add(label3);
getContentPane().setBackground(Color.white);
getContentPane().add(OK);
}
public static void main(String[] args) {
new HBA().setVisible(true);
}
}
Beside the JButton Problem: Can someone give me an advice how to build up from this and create the JOptionPane windows?