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. }

Identify 5 errors and give their Line Number, Error description and Statement after correction.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!