package Hangman;
import java.awt.EventQueue;
public class Hangman extends JFrame {
private JPanel contentPane;
private JTextField buchstabe;
private JTextField wort;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Hangman frame = new Hangman();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Hangman() {
boolean richtig;
setTitle("Hangman");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 408, 397);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
buchstabe = new JTextField();
buchstabe.setBounds(207, 11, 86, 20);
contentPane.add(buchstabe);
buchstabe.setColumns(1);
wort = new JTextField();
wort.setText("Wort");
wort.setBounds(10, 11, 86, 20);
contentPane.add(wort);
wort.setColumns(1);
final JTextArea nein = new JTextArea();
nein.setToolTipText("Buchstaben die nicht vorkommen\r\n");
nein.setBounds(255, 95, 135, 250);
contentPane.add(nein);
final JFrame frame = new JFrame();
int falsch=0;
final StringBuilder gesuchtVerdeckt = new StringBuilder ("____");
final JTextArea ta = new JTextArea();
ta.setBounds(10, 54, 378, 20);
contentPane.add(ta);
private boolean richtig;
final String Wort = wort.getText();
JButton pruefen = new JButton("Pr\u00FCfen");
pruefen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String Buchstabe = buchstabe.getText();
int index = Wort.indexOf(Buchstabe);
if(index > -1)
{
gesuchtVerdeckt.replace(index, index+1, Buchstabe);
richtig = true;
}
else
{
nein.setText(nein.getText()+Buchstabe);
richtig = false;
}
ta.setText(gesuchtVerdeckt.toString());
buchstabe.setText("");
}
});
pruefen.setBounds(303, 10, 89, 23);
contentPane.add(pruefen);
final String Text = ta.getText();
if (richtig==false)
{
falsch=falsch+1;
if (falsch==0)
{
JLabel imagelabel = new JLabel(new ImageIcon("0.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==1)
{
JLabel imagelabel = new JLabel(new ImageIcon("1.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==2)
{
JLabel imagelabel = new JLabel(new ImageIcon("2.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==3)
{
JLabel imagelabel = new JLabel(new ImageIcon("3.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==4)
{
JLabel imagelabel = new JLabel(new ImageIcon("4.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==5)
{
JLabel imagelabel = new JLabel(new ImageIcon("5.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==6)
{
JLabel imagelabel = new JLabel(new ImageIcon("6.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==7)
{
JLabel imagelabel = new JLabel(new ImageIcon("7.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==8)
{
JLabel imagelabel = new JLabel(new ImageIcon("8.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==9)
{
JLabel imagelabel = new JLabel(new ImageIcon("9.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
if (falsch==10)
{
JLabel imagelabel = new JLabel(new ImageIcon("10.gif"));
imagelabel.setBounds(10, 95, 216, 250);
contentPane.add(imagelabel);
frame.pack();
frame.show();
}
}
JButton button1 = new JButton("Ok");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
wort.enable(false);
wort.setVisible(false);
String Wort = wort.getText();
JLabel lbl_1 = new JLabel("Wortl\u00E4nge:"+ Wort.length()+" Zeichen");
lbl_1.setBounds(10, 77, 46, 14);
contentPane.add(lbl_1);
}
});
button1.setBounds(106, 10, 89, 23);
contentPane.add(button1);
JLabel lblNewLabel = new JLabel("Buchstaben die nicht vorkommen");
lblNewLabel.setFont(new Font("Arial", Font.BOLD, 11));
lblNewLabel.setBounds(207, 77, 183, 14);
contentPane.add(lblNewLabel);
}
}