Question: (b) Since all classes in Java inherit from the class Object, rewrite the code segment in Figure 1 below to take advantage of the concept

(b) Since all classes in Java inherit from the class Object, rewrite the code segment in Figure 1 below to take advantage of the concept of polymorphism. Declare all these GUI components as an array of Object and use a loop to call the appropriate methods based on the actual object form. JPanel pl = new JPanel(); JTextField tfl = new JTextField(5); JButton bl = new JButton ("OK"); JButton b2 = new JButton ("CANCEL"); pl.setBackground (Color.YELLOW); tfl.setBackground (Color.YELLOW); bl.setBackground (Color.YELLOW); b2.setBackground (Color.YELLOW); String temp = tfl.getText(); bl.addActionListener(this); b2.addActionListener(this); Figure 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
