Question: //java programming; Joyce Farrell; 8th ed //debugging exercises //output, need to fix //chapter 15 Advance GUI 1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.*;

//java programming; Joyce Farrell; 8th ed

//debugging exercises //output, need to fix

//chapter 15 Advance GUI

1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.awt.Color; 6 public class DebugFifteen1 extends JFrame implements ActionListener 7 { 8 JButton button1 = new JButton("Red"); 9 JButton button2 = new JButton("Pink"); 10 JButton button3 = new JButton("Orange"); 11 JButton button4 = new JButton("Yellow"); 12 JButton button5 = new JButton("Black"); 13 14 JPanel panel1 = new JPanel(new FlowLayout()); 15 JPanel panel2 = new JPanel(); 16 17 public DebugFifteen1() 18 { 19 setLayout(new GridLayout(1, 2)); 20 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 21 add(panel1); 22 add(panel2); 23 panel1.add(button1); 24 panel1.add(button1); 25 panel1.add(button1); 26 panel1.add(button1); 27 panel1.add(button1); 28 30 button1.addActionListener(); 31 button2.addActionListener(); 32 button3.addActionListener(); 33 button4.addActionListener(); 34 button5.addActionListener(); 35 setSize(400, 200); 36 setVisible(true); 37 } 38 @Override 39 public void actionPerformed(ActionEvent e) 40 { 41 Object source = e.getSource(); 42 if(source == button1) 43 panel2.setBackground(Color.RED); 44 else if(source == button2) 45 panel2.setBackground(Color.PINK); 46 else if(source == button3) 47 panel2.setBackground(Color.ORANGE); 48 else if(source == button4) 49 panel2.setBackground(Color.YELLOW); 50 else 51 panel2.setBackground(Color.YELLOW); 52 } 53 public static void main(String[] args) 54 { 55 DebugFifteen1 frame = new DebugFifteen1(); 56 } 57 } 58

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!