Java programming, Joyce farrell; 8th edDebugging Exercises 4 .docx

This preview shows page 1 - 4 out of 9 pages.

//java programming, Joyce farrell; 8th ed //Debugging Exercises/ 4 debugged //CHapter 15 Advanced GUI //easy if with 4 debugged it is related to each other. //ouput, need to fix error 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);

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture