Question

import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class BookReview extends JFrame implements ActionListener {

      private JLabel titleLabel;

      private JTextField titleTxtFd;

      private JComboBox typeCmb;

      private ButtonGroup ratingGP;

      private JButton processBnt;

      private JButton endBnt;

      private JButton clearBnt;

      private JTextArea entriesTxtAr;

      private JRadioButton excellentRdBnt;

      private JRadioButton veryGoodRdBnt;

      private JRadioButton fairRdBnt;

      private JRadioButton poorRdBnt;

      private String ratingString;

      private final String EXCELLENT = "Excellent";

      private final String VERYGOOD = "Very Good";

      private final String FAIR = "Fair";

      private final String POOR = "Poor";

      String lineSeparator = System.getProperty("line.separator");

      public BookReview(String name) {

            super(name);

            JPanel infoPanel = new JPanel();

            titleLabel = new JLabel("Title: ");

            infoPanel.add(titleLabel);

            titleTxtFd = new JTextField(20);

            infoPanel.add(titleTxtFd);

            typeCmb = new JComboBox();

            typeCmb.addItem("Novel");

            typeCmb.addItem("Short Stories");

            typeCmb.addItem("Essays");

            typeCmb.addItem("Poems");

            typeCmb.addItem("Biography");

            //Add two new entries

            typeCmb.addItem("Recipes");

            typeCmb.addItem("Travelogue");

            infoPanel.add(typeCmb);

            getContentPane().add(infoPanel, BorderLayout.NORTH);

            JPanel ratingPanel = new JPanel();

            ratingGP = new ButtonGroup();

            excellentRdBnt = new JRadioButton("Excellent");

            veryGoodRdBnt = new JRadioButton("Very Good");

            fairRdBnt = new JRadioButton("Fair");

            poorRdBnt = new JRadioButton("Poor");

            ratingGP.add(excellentRdBnt);

            ratingGP.add(veryGoodRdBnt);

            ratingGP.add(fairRdBnt);

            ratingGP.add(poorRdBnt);

            ratingPanel.add(excellentRdBnt);

            ratingPanel.add(veryGoodRdBnt);

            ratingPanel.add(fairRdBnt);

            ratingPanel.add(poorRdBnt);

            getContentPane().add(ratingPanel, BorderLayout.WEST);

            JPanel actionPanel = new JPanel(new GridLayout(1,0));

            processBnt = new JButton("process");

            endBnt = new JButton("end");

            clearBnt = new JButton("clear");

            actionPanel.add(processBnt);

            actionPanel.add(clearBnt);

            actionPanel.add(endBnt);

            getContentPane().add(actionPanel, BorderLayout.EAST);

            entriesTxtAr = new JTextArea(20, 20);

            getContentPane().add(entriesTxtAr, BorderLayout.SOUTH);

            pack();

            setVisible(true);

            processBnt.addActionListener(this);

            clearBnt.addActionListener(this);

            //hand write the code for registering the

            //other 6 components

            //in the space below. The 6 components are: endBnt,

            //excellentRdBnt, veryGoodRdBnt, fairRdBnt, poorRdBnt,

            //and typeCmb.

            //adding action listener for your six component by nirankar

            endBnt.addActionListener(this);

            excellentRdBnt.addActionListener(this);

            veryGoodRdBnt.addActionListener(this);

            fairRdBnt.addActionListener(this);

            poorRdBnt.addActionListener(this);

            typeCmb.addActionListener(this);

            addWindowListener(new WindowAdapter() {

                  public void windowClosing(WindowEvent event) {

                        System.exit(0);

                  }

            });

      }

      public void actionPerformed(ActionEvent event) {

            Object srcObj = event.getSource();

            if (srcObj == clearBnt) {

                  titleTxtFd.setText("");

            } else if (srcObj == endBnt) {

                  System.exit(0);

            } else if (srcObj == processBnt) {

                  entriesTxtAr.append(lineSeparator +

                              titleTxtFd.getText() + " " +

(String) typeCmb.getSelectedItem()

+ " " + ratingString);

            } else if (srcObj == excellentRdBnt) {

                  ratingString = EXCELLENT;

            } else if (srcObj == veryGoodRdBnt) {

                  ratingString = VERYGOOD;

            } else if (srcObj == fairRdBnt) {

                  ratingString = FAIR;

            } else if (srcObj == poorRdBnt) {

                  ratingString = POOR;

            }

      }

}

As indicated in the lecture, there are different ways of implementing an event handler. Inspect the code for BookReview() carefully, and answer the following question: when the “Close” button of the frame is pressed, a window close message is sent. In this case, which way of implementation is used (interface or adapter class)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

interface\;named\;WindowAdapter\;was\;used

Add a comment
Know the answer?
Add Answer to:
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame(&#3...

    Simple java questions Q2.java: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Q2 extends JFrame { public static void createAndShowGUI() { JFrame frame = new JFrame("Lab"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("Sans-serif", Font.BOLD, 20); JLabel label = new JLabel("Enter a word"); label.setFont(font); JTextField textField = new JTextField(10); textField.setFont(font); JButton button = new JButton("Enter"); button.setFont(font); Font font1 = new Font("Sans-serif", Font.BOLD, 30); JCheckBox sansSerif = new JCheckBox("Sans-serif"); sansSerif.setFont(font1); JCheckBox serif= new JCheckBox("Serif"); serif.setFont(font1); Font font2 = new Font("Sans-serif", Font.ITALIC, 15); JRadioButton...

  • package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{     JButton button1;     JLabel...

    package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{     JButton button1;     JLabel label1;     public int minutes=3;//initial time     public int time=minutes*60;//total amount of time in seconds only     public int seconds=time%60;     public String defaulttimeset="0"+Integer.toString(minutes)+":0"+Integer.toString(seconds);     public static void main(String[] args) {         Timing move=new Timing();         move.go();     }     public void go(){         JFrame frame=new JFrame();         frame.setBounds(50,50,400,400);         JPanel panel2=new JPanel();         button1=new JButton("Start Time");         panel2.add(button1);                 button1.setBounds(30,50,150,170);         frame.getContentPane().add(button1);...

  • GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public...

    GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame {    JButton loadButton, saveButton, drawButton;    JComboBox colorList, shapesList;    JTextField parametersTextField;       DrawingFrame() {        super("Drawing Application");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JToolBar toolbar = new JToolBar();        toolbar.setRollover(true);        toolbar.add(loadButton=new JButton("Load"));        toolbar.add(saveButton=new JButton("Save"));        toolbar.addSeparator();        toolbar.add(drawButton=new JButton("Draw"));               toolbar.addSeparator();        toolbar.addSeparator();        toolbar.add(new...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • Why when executed my frame does not contain what i have added to it? Here is...

    Why when executed my frame does not contain what i have added to it? Here is my code import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JPanel; @SuppressWarnings("serial") public class AddressBook1 extends JFrame implements ActionListener {    /**    *    */       JLabel name = new JLabel("Name: ");    JLabel address = new JLabel("Address: ");    JLabel phone = new JLabel("Phone: ");    JLabel email = new JLabel("Email: ");...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • Need some help fixing these compilation errors that start around line 20, thank you import javax.swing.*;...

    Need some help fixing these compilation errors that start around line 20, thank you import javax.swing.*; public class PropertyTax1 extends JFrame {    private static final int WIDTH = 400, HEIGHT = 300;       public PropertyTax1()    {        setTitle("Calculation of Property Taxes");        setSize(WIDTH, HEIGHT);        setVisible(true);        setDefaultCloseOperation(EXIT_ON_CLOSE);    } // end of the constructor method       public static void main(String[] args)    {        PropertyTax1 proptax = new PropertyTax1();   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT