Click here to Skip to main content
15,896,259 members

Comments by Basmala Haggag (Top 2 by date)

Basmala Haggag 18-Apr-21 9:29am View    
Deleted
Thanks for your answer I added a main method, but it still don't want to work. Hereby you will find my updated code.

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JTextField;



public class gamelevel1 {

public static void main(String[] args){

}

public class Pictureslevel1 {
public class PicturesLevel1 extends JFrame implements ActionListener {




private static final long serialVersionUID = 1L;
public JFrame frame;
public JPanel panel;


public JLabel label1;
public JLabel label2;
public JLabel label3;



public JButton next;
public JButton tryagain;


public JButton replay;
public JButton buttonA;
public JButton buttonB;
public JButton buttonC;



public ImageIcon tomatocolor;
public ImageIcon walvis;
ImageIcon zon;


public JTextField vraag;
public JTextField felicitatie;
public JTextField foutmelding;



public Timer hidePicture;
private int counter;



int index;



char[] answers = {

'A',
'B',
'C'
};


public PicturesLevel1() {



this.getContentPane().setLayout(new FlowLayout());
frame = new JFrame("colourgame");
frame.setSize(420, 420);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);



String[] questions = {
"Guess the color of the tomato",
"Guess the color of the whale",
"Guess the color of the sun"
};


foutmelding = new JTextField("Wrong, try again.");
felicitatie = new JTextField("Good job!");

foutmelding.setVisible(false);
felicitatie.setVisible(false);

foutmelding.setBounds(200, 390, 50, 20);
felicitatie.setBounds(200, 390, 50, 20);





tomatocolor = new ImageIcon("src/tomato.colour.jpg");
walvis = new ImageIcon("src/walvis.colour.jpg");
zon = new ImageIcon("src/zon.colour.jpg");


label1 = new JLabel(tomatocolor, JLabel.CENTER);
label2 = new JLabel(walvis, JLabel.CENTER);
label3 = new JLabel(zon, JLabel.CENTER);



vraag.setBounds(0,0,200,50);
vraag.setBackground(new Color(51,153,255));
vraag.setForeground(new Color(0,0,0));
vraag.setFont(new Font("Monospaced",Font.PLAIN,12));
vraag.setBorder(BorderFactory.createBevelBorder(1));
vraag.setHorizontalAlignment(JTextField.CENTER);
vraag.setText(questions[index]);
vraag.setVisible(true);




panel = new JPanel();
panel.setBounds(180,180, 100, 50);
panel.add(label1);
panel.add(label2);
label2.setVisible(false);
panel.add(label3);
label3.setVisible(false);



replay = new JButton();
replay.setBounds(100, 300, 100, 50);
replay.setText("Show again");
replay.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if (counter == 0) {
label1.setVisible(true);

} else if (counter == 1)
{
label2.setVisible(false);
} else{
label3.setVisible(false);
}

}
});
hidePicture.start();

frame.add(panel);

}


@Override
public void actionPerformed(ActionEvent e) {


}


}

}


}
Basmala Haggag 18-Apr-21 9:25am View    
Deleted
Thanks for your answer I added a main method, but it still don't want to work. Hereby you will find my updated code.

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JTextField;



public class gamelevel1 {

public static void main(String[] args){

}

public class Pictureslevel1 {
public class PicturesLevel1 extends JFrame implements ActionListener {




private static final long serialVersionUID = 1L;
public JFrame frame;
public JPanel panel;


public JLabel label1;
public JLabel label2;
public JLabel label3;



public JButton next;
public JButton tryagain;


public JButton replay;
public JButton buttonA;
public JButton buttonB;
public JButton buttonC;



public ImageIcon tomatocolor;
public ImageIcon walvis;
ImageIcon zon;


public JTextField vraag;
public JTextField felicitatie;
public JTextField foutmelding;



public Timer hidePicture;
private int counter;



int index;



char[] answers = {

'A',
'B',
'C'
};


public PicturesLevel1() {



this.getContentPane().setLayout(new FlowLayout());
frame = new JFrame("colourgame");
frame.setSize(420, 420);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);



String[] questions = {
"Guess the color of the tomato",
"Guess the color of the whale",
"Guess the color of the sun"
};


foutmelding = new JTextField("Wrong, try again.");
felicitatie = new JTextField("Good job!");

foutmelding.setVisible(false);
felicitatie.setVisible(false);

foutmelding.setBounds(200, 390, 50, 20);
felicitatie.setBounds(200, 390, 50, 20);





tomatocolor = new ImageIcon("src/tomato.colour.jpg");
walvis = new ImageIcon("src/walvis.colour.jpg");
zon = new ImageIcon("src/zon.colour.jpg");


label1 = new JLabel(tomatocolor, JLabel.CENTER);
label2 = new JLabel(walvis, JLabel.CENTER);
label3 = new JLabel(zon, JLabel.CENTER);



vraag.setBounds(0,0,200,50);
vraag.setBackground(new Color(51,153,255));
vraag.setForeground(new Color(0,0,0));
vraag.setFont(new Font("Monospaced",Font.PLAIN,12));
vraag.setBorder(BorderFactory.createBevelBorder(1));
vraag.setHorizontalAlignment(JTextField.CENTER);
vraag.setText(questions[index]);
vraag.setVisible(true);




panel = new JPanel();
panel.setBounds(180,180, 100, 50);
panel.add(label1);
panel.add(label2);
label2.setVisible(false);
panel.add(label3);
label3.setVisible(false);



replay = new JButton();
replay.setBounds(100, 300, 100, 50);
replay.setText("Show again");
replay.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if (counter == 0) {
label1.setVisible(true);

} else if (counter == 1){
la