Question

In: Computer Science

Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going...

Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going on in the program:

  1. Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labeled fields that display the number of words in the text and the average word length, as well as any other statistics you would like to add. The statistics area should also contain a button that, when pressed, computes the statistics for the current text content.

    Hint: Use a Scanner object to parse the text content. The .next() operation will get the next word.

  2. Design and implement an application that works as a stopwatch. Include a display that shows the time as it increments. The time value should be seconds only, to one decimal place. Include buttons that allow the user to start and stop the time, and to reset the display to zero. Arrange the components to present a nice user interface. The buttons should include a mnemonic shortcut. Only a single action listener should be used for the buttons.

Solutions

Expert Solution

Hi Dear

I'm writing the code which i have already tested and run on my pc.

Hope it helps and please like if you found my code helpful

Thanks

CODE:--

import java.awt.*;   

import java.awt.event.*;

import javax.swing.*; //importing different java classes

public class TextStatPanel extends JPanel implements ActionListener

{

    private JTextArea textArea;    //textArea for holding user text

    private JButton updateButton;    // to modify the value of text

    private JLabel[] stats; //labels to show the modifications of text

public static final String[] statLabels =

        {

"Total no. of words: ",

"avg. word length will be: "

        };

public TextStatPanel()

    {

   textArea = new JTextArea(" ");

textArea.setWrapStyleWord(true);

textArea.setLineWrap (true);

updateButton = new JButton   //make a button object to modify

            ("update text statistics");

        updateButton.addActionListener (this);    // action listener to handle the button event

JPanel statPane = new JPanel ();

        statPane.setBorder (BorderFactory.createTitledBorder      //setting border style

            ("Text Statistics"));

        statPane.setOpaque(false);     //making opaque false

        int n = statLabels.length;   //putting the statlabels to the panel

        statPane.add(updateButton);

        stats = new JLabel [n]; // alloting Jlabel to stats

        for (int i=0; i<n; ++i)

            {

JLabel label1 = new JLabel(statLabels[i]);

statPane.add(label1);

stats [i] = new JLabel ();

statPane.add(stats [i]);

            }

  JScrollPane scroll = new JScrollPane(textArea);

        scroll.setPreferredSize(new Dimension (350, 400));    //fixing scroll bar area

        scroll.setBorder(BorderFactory.createTitledBorder    // setting border title

("Text Container (Enter the text below)"));

   add (scroll); //adding scroll bar

add(statPane);

setBackground(new java.awt.Color(.33f, 0.45f, 0.65f)); //fixing background dimensions

setPreferredSize(new Dimension (400, 600));

updateStatistics(); //calling update statistics

    }

public void actionPerformed(ActionEvent event)

{

Object source = event.getSource();

if (source == updateButton)

        {

            updateStatistics();   

        }

    }

    private void updateStatistics()

    {

        String text = textArea.getText();

        String[] words = text.split(" ");

        float ave =

            (text.length() -words.length+0.0f)/words.length;

            stats[0].setText (String.valueOf(words.length));

            stats[1].setText (String.valueOf(ave));

    }//end of updateStatistics

}//end of class TextStatPanel

import javax.swing.JFrame;   //TextStatDriver.java

public class TextStatDriver

{

   

    public static void main(String[] args)    //Creates and displays the main program

    {

        JFrame frame = new JFrame("Tool for calculating " +

                       "basic ststistic segment of text:");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add( new TextStatPanel());

        frame.pack();

        frame.setVisible(true);

}

}


Related Solutions

Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting:...
Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting: a. Write a function that writes a series of random Fahrenheit temperatures and their corresponding Celsius temperatures to a tab-delimited le. Use 32 to 212 as your temperature range. From the user, obtain the following: 1) The number of temperatures to randomly generate. 2) The name of the output file. b. Write a function that reads a file produced by part (a). Focusing only...
*****Using Java Write a program that finds the standard deviation while also using a graphical user...
*****Using Java Write a program that finds the standard deviation while also using a graphical user interface.
I am in beginners java course so using the most simple/basic JAVA please complete the following...
I am in beginners java course so using the most simple/basic JAVA please complete the following CODE SEGMENTS. (2 parts) FIRST PART: Using ITERATIVE create a METHOD MAX that returns the max element in an ArrayList of ints and prints all of the elements. *you have to use an iterative in the method.* (just need to write the METHOD ONLY not a whole program(will do in 2nd part), assume you are given any numbers/integers. SECOND PART: Now write a class...
In Java please. I put down my code and what I was able to achieve so...
In Java please. I put down my code and what I was able to achieve so far: public class Animal {   private String gender; //stores the gender of the animal    private String type; //stores the type of the animal(bear of fish)    private int strength; //stores the strength of the animal    public Animal() {        gender = "none";        type = "none";        strength = 0;    }        public Animal (String g, String...
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases. We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance. The program must allow the following options: a) Create an account: request the account information and save it in the database. b) Enter the ATM: it will allow you to request the account number and will...
create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
7. What are abstract classes and interfaces in Java? What are they used for, and what...
7. What are abstract classes and interfaces in Java? What are they used for, and what are they comprised of? Clearly explain the difference between the two.
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user...
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user for the number of elements, not to exceed arraySize = 20 (put appropriate input validation) Ask the user for the type of data they will enter - EnglishGrade or MathGrade objects. Use your EnglishGrade and MathGrade classes Based on the input, create an appropriate array for the data to be entered. Write a helper function called recursionMergeSort such that: It is a standalone function...
B has to be matched with A so please I need both in Java. the previous...
B has to be matched with A so please I need both in Java. the previous project mean A A. Write a class that maintains the top ten scores for a game application, implementing the add and remove methods but using a singly linked list instead of an array. B. Perform the previous project, but use a doubly linked list. Moreover, your implementation of remove(i) should make the fewest number of pointer hops to get to the game entry at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT