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...
Please write a java program (using dialog box statements for user input) that has the following...
Please write a java program (using dialog box statements for user input) that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled,...
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....
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
(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...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT