Respuesta :
Answer:
Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol
Explanation:
Below is the Java Swing implementation of the assignment.
=========================== LongDistance.java ====================================
import java.awt.GridLayout;
import javax.swing.*;
public class LongDistance extends JFrame{
Â
 /**
 *
 */
 public static float rate;
 public static float minutes;
 public static float total;
Â
 LongDistance(){
  Â
  Â
   RatePanel rp = new RatePanel();
  Â
   MinutesPanel mp = new MinutesPanel();
  Â
   ButtonsPanel bp = new ButtonsPanel();
  Â
   this.setLayout(new GridLayout(3, 1));
  Â
Â
  Â
   this.add(rp);
   this.add(mp);
   this.add(bp);
      Â
   this.setDefaultCloseOperation(EXIT_ON_CLOSE);
   this.setSize(250, 250);
   this.setVisible(true);
 }
Â
}
============================ RatePanel.java ==================================
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
public class RatePanel extends JPanel implements ActionListener {
 /**
 *
 */
 private JRadioButton jr1, jr2, jr3;
 RatePanel(){
  Â
   Border panelBorder = BorderFactory.createTitledBorder("Select a Rate Category");
  Â
  Â
   jr1 = new JRadioButton("Daytime ($0.7) per minute");
   jr2 = new JRadioButton("Evening ($0.12) per minute");
   jr3 = new JRadioButton("Off-Peak ($0.05) per minute");
   ButtonGroup bg = new ButtonGroup();
  Â
   this.setLayout(new GridLayout(3,1));
   this.setBorder(panelBorder);
   this.setPreferredSize(new Dimension(800, 150));
  Â
   this.add(jr1);
   this.add(jr2);
   this.add(jr3);
  Â
   bg.add(jr1);
   bg.add(jr2);
   bg.add(jr3);
  Â
   jr1.addActionListener(this);
   jr2.addActionListener(this);
   jr3.addActionListener(this);
    Â
 }
 "at"Override
 public void actionPerformed(ActionEvent arg0) {
   // TODO Auto-generated method stub
  Â
   if(arg0.getSource() == jr1){
     LongDistance.rate = 0.07f;
   }
  Â
   if(arg0.getSource() == jr2){
     LongDistance.rate = 0.12f;
   }
  Â
   if(arg0.getSource() == jr3){
     LongDistance.rate = 0.05f;
   }
  Â
 }
}
=============================== MinutesPanel.java =============================
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.DocumentListener;
public class MinutesPanel extends JPanel implements KeyListener{
 JTextField jt;
Â
 MinutesPanel(){
   Border panelBorder = BorderFactory.createTitledBorder("Time Of Call");
  Â
   this.setLayout(new GridLayout(1, 2));
  Â
   JLabel jl = new JLabel("Minutes: ");
   jt = new JTextField();
  Â
jt.setBounds(50,50,150,20);
   this.setPreferredSize(new Dimension(10, 10));
   this.setBorder(panelBorder);
   this.add(jl);
   this.add(jt);
  Â
   jt.addKeyListener(this);
Â
  Â
  Â
  Â
 }
 "at"Override
 public void keyPressed(KeyEvent arg0) {
   // TODO Auto-generated method stub
  Â
 }
 "at"Override
 public void keyReleased(KeyEvent arg0) {
   // TODO Auto-generated method stub
   if(jt.getText() != "")
     LongDistance.minutes = Float.parseFloat(jt.getText());
 }
 "at"Override
 public void keyTyped(KeyEvent arg0) {
   // TODO Auto-generated method stub
  Â
  Â
 }
Â
}
============================= ButtonsPanel.java ============================
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class ButtonsPanel extends JPanel implements ActionListener{
 JButton calculate;
 JButton exit;
 ButtonsPanel(){
   calculate = new JButton("Calculate Charges");
   exit = new JButton("Exit");
  Â
   this.add(calculate);
   this.add(exit);
  Â
   calculate.addActionListener(this);
   exit.addActionListener(this);
  Â
 }
 "at"Override
 public void actionPerformed(ActionEvent arg0) {
   // TODO Auto-generated method stub
  Â
   if(arg0.getSource() == calculate){
          Â
     System.out.println("r " + LongDistance.rate);
     System.out.println("m " + LongDistance.minutes);
    Â
     LongDistance.total = LongDistance.rate * LongDistance.minutes;
     JOptionPane.showMessageDialog(null, "Total Charges: " +LongDistance.total);
    Â
   }
  Â
   if(arg0.getSource() == exit){
     System.exit(0);
   }
 }
}
============================ App.java==============================
public class App {
 public static void main(String[] args) {
  Â
   LongDistance ld = new LongDistance();
  Â
 }
}
Check the output below
