Question

In: Advanced Math

Using Java (Swing) language(please hard code)... Create a program that has a textfield for the user...

Using Java (Swing) language(please hard code)... Create a program that has a textfield for the user to type in a set of input. Below that textfield have the following controls to show string manipulations:

(1) A button that will change the entire textfield’s current text to uppercase.

(2) A button with its own textfield for a search value, that will tell the position the search value appears in the textfield above.

(3) A button that reports the current number of characters in the textfield above.

Solutions

Expert Solution

Program:

import javax.swing.*;
import java.awt.event.*;

class StringManipulations
{
public static void main(String args[])
{
JFrame frm=new JFrame("String Manipulations!!");
frm.setLayout(null);

JTextField txtInput=new JTextField();
txtInput.setBounds(180,40,120,40);
frm.add(txtInput);

JButton btn1=new JButton("Uppercase");
btn1.setBounds(40,110,130,30);
frm.add(btn1);

JButton btn2=new JButton("Search");
btn2.setBounds(180,110,110,30);
frm.add(btn2);

JButton btn3=new JButton("CharactersCount");
btn3.setBounds(300,110,140,30);
frm.add(btn3);

JLabel lblOutput=new JLabel();
lblOutput.setBounds(40,180,260,40);
frm.add(lblOutput);

btn1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String output="Uppercase : ";
String str=txtInput.getText();
str=str.toUpperCase();
output=output+str;
lblOutput.setText(output);
}
});

btn2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String output="Position of entered search value: ";
String str=txtInput.getText();

JFrame f1=new JFrame();
String searchValue=JOptionPane.showInputDialog(f1,"Enter search character's position: ");
int position=str.indexOf(searchValue);
output=output+position;
lblOutput.setText(output);
}
});

btn3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String output="Number of characters : ";
String str=txtInput.getText();
int len=str.length();
int count=0;
for(int i=0;i<len;i++)
{
count++;
}
output=output+count;
lblOutput.setText(output);
}
});

frm.setVisible(true);
frm.setSize(500,350);

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Output:


Related Solutions

Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Code using assembly language Create a program using the Irvine32 procedures were the user can input...
Code using assembly language Create a program using the Irvine32 procedures were the user can input a list of 32-bit unsigned integers an “x” number of times, then display these integers to the console in reverse order. Hint: Use loops and PUSH & POP instructions. Extra Challenge: Inform the user with a message what to do; also, tell them what they are seeing.
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
In java, Create a GUI which works as an accumulator 1. There is a textfield A...
In java, Create a GUI which works as an accumulator 1. There is a textfield A which allows user to enter a number 2. There is also another textfield B with value start with 0. 3. When a user is done with entering the number in textfield A and press enter, calculate the sum of the number in textfield B and the number user just entered in textfield A, and display the updated number in textfield B
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT