Question
Identify errors and correct them of the following Java program: (10 marks) 1. import java.swing.*; 2. import java.awt.*; 3. import java.awt.event.* 4. public class ColorWindow
Identify errors and correct them of the following Java program: (10 marks)
1. import java.swing.*;
2. import java.awt.*;
3. import java.awt.event.*
4. public class ColorWindow extends Frame
5. {
6. private JLabel messageLabel;
7. private JButton redButton;
8. private JPanel panel;
9. private final int WINDOW_WIDTH = 200;
10. private final int WINDOW_HEIGHT = 125;
11. public ColorWindow
12. {
13. setTitle("Colors");
14. setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
15. setDefaultCloseOperation(JFrame.EXIT);
16. messageLabel = new JLabel("Click the button to " + "apply red color.");
17. redButton = new JButton("Red");
18. redButton.addActionListener(new RedButtonListener());
19. panel = new JPanel();
20. panel.add(messageLabel);
21. panel.add(redButton);
22. add(panel);
23. setVisible(true);
24. }
25. private class RedButtonListener implements ActionListener
26. {
27. public void actionPerformed(ActionEvent e)
28. {
29. panel.setBackground(Color.RED);
30. messageLabel.setForeground(Color.BLUE);
31. }
32.
33. public static void main(String[] args)
34. {
35. new ColorWindow();
36. }
37. }
One error is already identified for you as shown below:
Line Number: 3
Error description: Missing semicolon
Statement after correction: import java.awt.event.*;
Identify 5 other errors and give their Line Number, Error description and Statement after correction.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started