
Dear sir/medam i would like to know how to use the java string class method my programm have four button,(enter the text) that first button is To upper case,second button is lower case Third button is Reverse the order, Fourth button is Find length of text. and there are panels. Please help me. i want to write the code on this program. please share ur idea.

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
class StringDemo extends JFrame{
JLabel label;
final JTextField text;
StringDemo(){
setTitle("Login Form");
setLayout(null);
label = new JLabel("Enter Text");
text = new JTextField(20);
JButton b1=new JButton("To Uppercase");
JButton b2=new JButton("To Lowercase");
JButton b3=new JButton("Reverse Order");
JButton b4=new JButton("Length of Text");
JPanel p1=new JPanel(new GridLayout(1,1));
JPanel p2=new JPanel(new GridLayout(1,4));
p1.add(label);
p1.add(text);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
JFrame f=new JFrame();
f.add(p1,BorderLayout.NORTH);
f.add(p2,BorderLayout.CENTER);
f.setVisible(true);
f.pack();
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=text.getText();
String uppercase=st.toUpperCase();
JOptionPane.showMessageDialog(null,"Text in Uppercase: "+uppercase);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=text.getText();
String lowercase=st.toLowerCase();
JOptionPane.showMessageDialog(null,"Text in Lowercase: "+lowercase);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=text.getText();
String reverse=new StringBuffer(st).reverse().toString();
JOptionPane.showMessageDialog(null,"Text in reverse: "+reverse);
}
});
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=text.getText();
int len=st.length();
JOptionPane.showMessageDialog(null,"Length of Text: "+len);
}
});
}
public static void main(String []args){
new StringDemo();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.