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, commenting should be proper, along with testing for valid and invalid inputs: Develop a...
Using java, commenting should be proper, along with testing for valid and invalid inputs: 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 labelled fields that display the number of words in the...
*****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...
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...
(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.
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT