Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Typing Program: Tuning a Crucial Skill in the Computer Age) Typing quickly and

ID: 3804624 • Letter: #

Question

(Typing Program: Tuning a Crucial Skill in the Computer Age) Typing quickly and correctly is an essential skill for working effectively with computers and the Internet. In this exercise, you’ll build a GUI application that can help users learn to “touch type” (i.e., type correctly without looking at the keyboard). The application should display a virtual keyboard (Fig. 14.50) and should allow the user to watch what he or she is typing on the screen without looking at the actual keyboard. Use JButtons to represent the keys. As the user presses each key, the application highlights the corresponding JButton on the GUI and adds the character to a JTextArea that shows what the user has typed so far. [Hint: To highlight a JButton, use its setBackground method to change its background Fig. 14.49 | Interface for drawing shapes. 630 Chapter 14 GUI Components: Part 1 color. When the key is released, reset its original background color. You can obtain the JButton’s original background color with the getBackground method before you change its color.]

Explanation / Answer

/*
* Hi.. submitting this answer in 2hrs in tough for me,i feel i almost covered what you described,feel
* free to comment if you are facing any difficulty
* Thank You ,all The Best :-)
*/

package com;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;

import javax.swing.JButton;

public class MyButton extends JButton implements ActionListener{
  
   MyButton(String text) {
       super(text);
       setPreferredSize(new Dimension(50, 50));
       addActionListener(this);
   }
  
   protected void paintComponent(Graphics g)
      {
        if (getModel().isArmed()) {
          g.setColor(Color.lightGray);
        } else {
          g.setColor(getBackground());
        }
        g.fillOval(0, 0, getSize().width-1,getSize().height-1);

        super.paintComponent(g);
      }

      protected void paintBorder(Graphics g) {
        g.setColor(getForeground());
        g.drawOval(0, 0, getSize().width-1,     getSize().height-1);
      }

      Shape shape;
      public boolean contains(int x, int y) {
        if (shape == null ||
          !shape.getBounds().equals(getBounds())) {
          shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
        }
        return shape.contains(x, y);
      }

   @Override
   public void actionPerformed(ActionEvent e) {
       // TODO Auto-generated method stub
      
   }}