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.
Create a java program that has a code file with main() in it and another code...
Create a java program that has a code file with main() in it and another code file with a separate class. You will be creating objects of the class in the running program, just as the chapter example creates objects of the Account class. Your system handles employee records and processes payroll for them. Create a class called Employee that holds the following information: first name, last name, monthly salary, and sales bonus. The class should have all the gets...
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,...
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 Language: Using program created in this lesson as a starting point, create a circular list...
Java Language: Using program created in this lesson as a starting point, create a circular list with at least four nodes. A circular list is one where the last node is made to point to the first. Show that your list has a circular structure by printing its content using an iterative structure such as a while. This should cause your program to go into an infinite loop so you should include a conditional that limits the number of nodes...
Please code the following, using the language java! Build a simple calculator that ignores order of...
Please code the following, using the language java! Build a simple calculator that ignores order of operations. This “infix” calculator will read in a String from the user and calculate the results of that String from left to right. Consider the following left-to-right calculations: "4 + 4 / 2" "Answer is 4" //not 6, since the addition occurs first when reading from left to right “1 * -3 + 6 / 3” “Answer is 1” //and not -1Start by copying...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT