15,896,259 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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