exam

exam

Write a Java applet that that takes in a sentence from the user through a text field and append the sentence to a text area in individual line when the button labeled APPEND is clicked. When the sentence is appended to the text area, the program will also count the number of the word "the" or "The" that appeared and display the total count in another text field. Provide another button labeled CLEAR to clear the sentence input text field. The panel that contains all the GUI components should be separated in a class, while the applet that invokes this panel should be in another class.

View Answers

March 7, 2011 at 5:40 PM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Example
{
    Example(){  
    JFrame f=new JFrame();
    f.setLayout(null);
    JLabel label1=new JLabel("String: ");
    JLabel label2=new JLabel("Append: ");
    JLabel label3=new JLabel("Count Words: ");
    final JTextField text1=new JTextField(20);
    final JTextArea area=new JTextArea(5,20);
    final JTextField text2=new JTextField(20);
    JButton b=new JButton("Append");
    JButton b1=new JButton("Clear");
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            String str=text1.getText();
        int count=0;
        area.setText(str);
        String arr[]=str.split(" ");
        for(int i=0;i<arr.length;i++){
            if(arr[i].equals("the")||arr[i].equals("The")){
                count++;
            }
        }
        text2.setText(Integer.toString(count));
        }
    });
    b1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            text1.setText("");
            text2.setText("");
            area.setText("");
        }
    });
        label1.setBounds(10,10,100,20);
        text1.setBounds(150,10,200,20);

        label2.setBounds(10,40,100,20);
        area.setBounds(150,40,200,60);

        label3.setBounds(10,120,100,20);
        text2.setBounds(150,120,200,20);

        b.setBounds(10,150,100,20);
        b1.setBounds(150,150,100,20);

        f.add(label1);
        f.add(text1);
        f.add(label2);
        f.add(area);
        f.add(label3);
        f.add(text2);
        f.add(b);
        f.add(b1);
        f.setVisible(true);
        f.setSize(400,250);
    }
}
    class StringExample8{
    public static void main(String[] args) {
        new Example();
    }
}









Related Tutorials/Questions & Answers:
Online Exam
Online Exam  I want to write a program for Exam with multiple answers program can read answers one by one and it shows the total marks at the end how it can implement Help me
Exam help
Exam help  A table exists which has a primary key field which is numeric, and is called Id. When inserting a new record into this table you should ensure that the Id used is the next available Id. Discuss how you would
Advertisements
exam
SCJA Syllabus And Exam Fees
SCJA Syllabus And Exam Fees  What is SCJA syllabus and exam fees for SCJA and also exam dates in 2012 for SCJA? Thanking You (In Advance
Exam Dates Of SCJP 2011
Exam Dates Of SCJP 2011  List all the exam dates of scjp that will be held in 2011
ModuleNotFoundError: No module named 'exam'
ModuleNotFoundError: No module named 'exam'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'exam' How to remove the ModuleNotFoundError: No module named 'exam' error
ModuleNotFoundError: No module named 'exam'
ModuleNotFoundError: No module named 'exam'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'exam' How to remove the ModuleNotFoundError: No module named 'exam' error
SCJP exam date 2011
SCJP exam date 2011  Please provide me the list of exam dates that will be in the yr. 2011 for SCJP.... Thank You In Adv
online exam portal
online exam portal  i am thinking of developing a small online exam pattern with multipe choice questions , can u please give me any idea of how to start
jsp online exam...
jsp online exam...  Plz provide me front end design
Part I. Exam Objectives
Part I. Exam ObjectivesPrev   Next    Exam Objectives Learn how to develop and deploy enterprise application
ONLINE EXAM CODE SPLIT
ONLINE EXAM CODE SPLIT  hi.. im developing online exam for c programming in jsp.. i read the question from database as a string suppose String ques="#include<stdio.h>main(){int i;for(i=0;<100;i++){printf("hai
ModuleNotFoundError: No module named 'CUP-EXAM'
ModuleNotFoundError: No module named 'CUP-EXAM'  Hi, My Python...-EXAM' How to remove the ModuleNotFoundError: No module named 'CUP-EXAM... to install padas library. You can install CUP-EXAM python with following
ModuleNotFoundError: No module named 'exam-scheduler'
ModuleNotFoundError: No module named 'exam-scheduler'  Hi, My... named 'exam-scheduler' How to remove the ModuleNotFoundError: No module named 'exam-scheduler' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'notebook-exam'
ModuleNotFoundError: No module named 'notebook-exam'  Hi, My... 'notebook-exam' How to remove the ModuleNotFoundError: No module named 'notebook-exam' error? Thanks   Hi, In your python
Part I. Exam Objectives
Part I. Exam ObjectivesPrev   Next    Exam ObjectivesVisit http://java.boot.by  for the updates.    Prev Up NextPreface Home 
how to create online exam in jsp and database
how to create online exam in jsp and database  learing stage ,want to know how to create online exam
ModuleNotFoundError: No module named 'odoo9-addon-openeducat-exam'
ModuleNotFoundError: No module named 'odoo9-addon-openeducat-exam'  ...: No module named 'odoo9-addon-openeducat-exam' How to remove the ModuleNotFoundError: No module named 'odoo9-addon-openeducat-exam' error? Thanks
ModuleNotFoundError: No module named 'xblock-proctor-exam'
ModuleNotFoundError: No module named 'xblock-proctor-exam'  Hi, My... named 'xblock-proctor-exam' How to remove the ModuleNotFoundError: No module named 'xblock-proctor-exam' error? Thanks   Hi
ModuleNotFoundError: No module named 'xblock-proctor-exam'
ModuleNotFoundError: No module named 'xblock-proctor-exam'  Hi, My... named 'xblock-proctor-exam' How to remove the ModuleNotFoundError: No module named 'xblock-proctor-exam' error? Thanks   Hi
ModuleNotFoundError: No module named 'bee-django-exam'
ModuleNotFoundError: No module named 'bee-django-exam'  Hi, My... named 'bee-django-exam' How to remove the ModuleNotFoundError: No module named 'bee-django-exam' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'canadian-ham-exam'
ModuleNotFoundError: No module named 'canadian-ham-exam'  Hi, My... named 'canadian-ham-exam' How to remove the ModuleNotFoundError: No module named 'canadian-ham-exam' error? Thanks   Hi, In your
Version of com.basistech>pax-exam-test-composite dependency
List of Version of com.basistech>pax-exam-test-composite dependency
Online exam using c# and SQL server
Online exam using c# and SQL server  hello, i'm making the (window... then client must get the relevant message and exam on client must gets stopped, until server didn't start the same exam. so to do that what should I do? plz help
online exam
online exam
online exam
online exam
online exam
online exam
online exam
on line exam
written exam
Maven Dependency pax-exam-test-composite >> 0.0.6
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.6 in your project
Maven Dependency pax-exam-test-composite >> 0.0.1
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.1 in your project
Maven Dependency pax-exam-test-composite >> 0.0.11
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.11 in your project
Maven Dependency pax-exam-test-composite >> 0.0.5
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.5 in your project
Maven Dependency pax-exam-test-composite >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.2 in your project
Maven Dependency pax-exam-test-composite >> 0.0.8
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.8 in your project
Maven Dependency pax-exam-test-composite >> 0.0.7
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.7 in your project
Maven Dependency pax-exam-test-composite >> 0.0.9
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.9 in your project
Maven Dependency pax-exam-test-composite >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.3 in your project
Maven Dependency pax-exam-test-composite >> 0.0.10
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.10 in your project
Maven Dependency pax-exam-test-composite >> 0.0.4
You should include the dependency code given in this page to add Maven Dependency of com.basistech >> pax-exam-test-composite version0.0.4 in your project
Maven Repository/Dependency: com.basistech | pax-exam-test-composite
Maven Repository/Dependency of Group ID com.basistech and Artifact ID pax-exam-test-composite. Latest version of com.basistech:pax-exam-test-composite dependencies. # Version Release Date
Should we go for javascript or applets for online exam project using java
Should we go for javascript or applets for online exam project using java  Hi, I am new to java and i am working on online examination project.As soon as the candidate login successfully a window pop up should appear
jsp online exam
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam-test-composite version 0.0.11
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam... com.basistech:pax-exam-test-composite:0.0.11 Java library in your project...-exam-test-composite version 0.0.11 In this section have given the dependency code
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam-test-composite version 0.0.8
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam... com.basistech:pax-exam-test-composite:0.0.8 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for pax-exam
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam-test-composite version 0.0.5
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for pax-exam... com.basistech:pax-exam-test-composite:0.0.5 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for pax-exam

Ads