Explain this code, please. private JButton a = new JButton(\"A\"); private JButt
ID: 3583065 • Letter: E
Question
Explain this code, please.
private JButton a = new JButton("A");
private JButton b = new JButton("BBBBBBBBBB");
private JButton c = new JButton("C");
private JButton hello = new JButton("Hello");
private JButton replace = new JButton("Replace");
private JCheckBox sensitive = new JCheckBox("Case sensitive?");
private JFrame frame = new JFrame();
private JLabel listLabel = new JLabel();
private JTextField from = new JTextField(8);
private JTextField to = new JTextField(8);
JPanel south = new JPanel(new GridLayout(1, 3));
south.add(a);
south.add(b);
south.add(c);
JPanel north = new JPanel(new FlowLayout());
north.add(from);
north.add(replace);
north.add(to);
JPanel center = new JPanel(new BorderLayout());
center.add(north, BorderLayout.NORTH);
center.add(listLabel, BorderLayout.CENTER);
center.add(sensitive, BorderLayout.SOUTH);
frame.add(hello, BorderLayout.WEST);
frame.add(south, BorderLayout.SOUTH);
frame.add(center, BorderLayout.CENTER);
frame.setTitle("Lay it out");
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Finish the following Java program that creates a GUI and shows it on the screen. Create the window with a layout as pictured and fill it with the components necessary. The window's title should be "Lay it out" and initially the window should be sized exactly to fit the components inside it. When the window is closed, the program should terminate. The following screenshots show the program's initial appearance and after resizing the window: Lay it out Replace l Replace Hello o, be, or, not, to, be, hamlet] Case sensitive? Hello to, be, or, not, to, be, hamlet] Case sensitive? Lay it out O He to, be, h [to, be, or, not, Case sensitive? BB Start from the following partial code. Complete the class by writing your answer on the next page. Lay it out Replace N See Hello to, see, or, not, to, see, hamlet] Case sensitive?Explanation / Answer
private JButton a = new JButton("A");
//creating a button with name A
private JButton b = new JButton("BBBBBBBBBB");
//creating a button with name BBBBBBBBB
private JButton c = new JButton("C");
//creating a button with name c
private JButton hello = new JButton("Hello");
//creating a button with name hello
private JButton replace = new JButton("Replace");
//creating a button with name Replace
private JCheckBox sensitive = new JCheckBox("Case sensitive?");
//creating a checkbox with name case sensitive
private JFrame frame = new JFrame();
//Constructs a new frame that is initially invisible.
private JLabel listLabel = new JLabel();
//Creates a JLabel instance with no image and with an empty string for the title.
private JTextField from = new JTextField(8);
// display the result of the action based from which button is pressed
private JTextField to = new JTextField(8);
// display the result of the action based upto which button is pressed
JPanel south = new JPanel(new GridLayout(1, 3));
// for the left panel you could use GridLayout(3,1) and then add the buttons, text fields.. this will give you three lines. if you want to have the buttons and text fields horizontally you can use GridLayout(1,3) this will give you three columns
south.add(a); //left panel
south.add(b); //left panel
south.add(c); //left panel
JPanel north = new JPanel(new FlowLayout());
here the FlowLayout class puts components in a row, sized at their preferred size. If the horizontal space in the container is too small to put all the components in one row, the FlowLayout class uses multiple rows
north.add(from); //adding panel
north.add(replace); //adding panel
north.add(to); //adding panel
JPanel center = new JPanel(new BorderLayout());
//add the JPanel to the Center of your panel
center.add(north, BorderLayout.NORTH); //borderr layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center
center.add(listLabel, BorderLayout.CENTER);
center.add(sensitive, BorderLayout.SOUTH);
frame.add(hello, BorderLayout.WEST);
frame.add(south, BorderLayout.SOUTH);
frame.add(center, BorderLayout.CENTER);
frame.setTitle("Lay it out"); // tile nme
frame.pack(); //pack method sizes the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// close the program
frame.setVisible(true);//shows the frame
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.