Question: please explain this code? //Program for Customer 05 dislikes import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CustomerDislikes extends JFrame implements ActionListener //Creating JFrame and
please explain this code?
//Program for Customer 05 dislikes
import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class CustomerDislikes extends JFrame implements ActionListener //Creating JFrame and Handling Button Event Listener { JPanel panel; JLabel l[]; //An array of JLabels JButton btnremove; int lblcount; //Label counting index 0 to 4 public CustomerDislikes() { l=new JLabel[5]; //Allocation of JLabel lblcount=0; panel=new JPanel(new GridLayout(6,1)); //Creating Grid layout with 6 rows and 1 column panel.setPreferredSize(new Dimension(500,500)); //Size of JPanel
//Creating 05 JLables l[0]=new JLabel("1.Too expensive"); l[1]=new JLabel("2.No expected quality"); l[2]=new JLabel("3.Date is expired"); l[3]=new JLabel("4.Not prominent brand"); l[4]=new JLabel("5.Bad feedback");
//Adding them to JPanel for(int i=0;i<5;i++) panel.add(l[i]);
//Adding JButton with "Remove" as text btnremove=new JButton("Remove"); panel.add(btnremove); btnremove.addActionListener(this); add(panel); setTitle("Customer Dislikes JFrame"); //Title of JFrame window setSize(500,500); //Size of JFrame setVisible(true); //Visible True } //Called when button is clicked public void actionPerformed(ActionEvent ae) {
//Remove/hide if lblcount is below 05 if(lblcount<5) l[lblcount++].setVisible(false); } public static void main(String args[]) { new CustomerDislikes(); //Creating object instance of JFrame } }
//Program for Customer 05 dislikes
import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class CustomerDislikes extends JFrame implements ActionListener //Creating JFrame and Handling Button Event Listener { JPanel panel; JLabel l[]; //An array of JLabels JButton btnremove; int lblcount; //Label counting index 0 to 4 public CustomerDislikes() { l=new JLabel[5]; //Allocation of JLabel lblcount=0; panel=new JPanel(new GridLayout(6,1)); //Creating Grid layout with 6 rows and 1 column panel.setPreferredSize(new Dimension(500,500)); //Size of JPanel
//Creating 05 JLables l[0]=new JLabel("1.Too expensive"); l[1]=new JLabel("2.No expected quality"); l[2]=new JLabel("3.Date is expired"); l[3]=new JLabel("4.Not prominent brand"); l[4]=new JLabel("5.Bad feedback");
//Adding them to JPanel for(int i=0;i<5;i++) panel.add(l[i]);
//Adding JButton with "Remove" as text btnremove=new JButton("Remove"); panel.add(btnremove); btnremove.addActionListener(this); add(panel); setTitle("Customer Dislikes JFrame"); //Title of JFrame window setSize(500,500); //Size of JFrame setVisible(true); //Visible True } //Called when button is clicked public void actionPerformed(ActionEvent ae) {
//Remove/hide if lblcount is below 05 if(lblcount<5) l[lblcount++].setVisible(false); } public static void main(String args[]) { new CustomerDislikes(); //Creating object instance of JFrame } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
