hi guys, hope you are doing very well. I've been working on a program that if I enter lowercase letters in one textField the other should display it in capital letters with the help of Event Handling but I am constantly getting these two errors. I'm a beginner so would be really nice if you could help me out.

Recommended Answers

All 13 Replies

somehow I can't post the code as it says post the code by pressing the code button in the editer toolbar but when I press nothing happens.

is there any other way I could post my code here?

Code posting does work - start your message, click the code button you should see a new window in which you can post your code. If that's not working can you post a screen shot that shows what your'e trying?

it's still not working but I took a snapshot how'd I post it?

[Edit: code received via PM and posted here by JC]

import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

class cls extends JFrame implements ActionListener

public cls(){
super("MY First Event Handling");
setLayout(new FlowLayout());
JTextField atextfield=new JTextField();

JTextField btextfield=new JTextField();


public void actionPerformed(ActionEvent r){
String action=r.getActionCommand();
String data = r.getText();
String out = data.toUpperCase();



public static void main(String arg[])
cls obj=new cls();

OK, I posted the code for you (just clicked the "code" button and pasted it in!).
Now, what exactly are the two errors you referred to?

cannot find Symbol r.getText()
line no:27

Also as I'm a very new to Event Handling I'd apperciate if you could help me out in the other code and see if my logic is right..

and Thanks James.

r is defined as an ActionEvent (line 25) and ActionEvents do not have a getText() method, so that's why the compiler can't find it.
Probably what you want to do is to get the text from atextfield into a String, convert that to upper case, and set that text into btextfield.

Exactly that what sir I want to do..how would I do that I need help..

If I write <if (r.getSourcee==abtn) then do this> I get an error "cannot find Symbol" What I'm missing there..

getSource is a method, so the syntax is if (r.getSource() == abtn)

Fot getting the text fro a text field and updating a text field you can use the getText() and setText(String s) methods that every JTextField has.

ok thanks I got it working but is it possible to convert the string we get from atextfield in ActionPerformed to Upper or LowereCase without the inbuilt in methods?

Java Strings are made up of chars. A char is a 16 bit number representing a character in UniCode. (Unicode has the same values as ASCII for English letters.) If you find a UniCode or ASCII chart on the web you can see what the numeric values for a...z A..Z are, and you can work out the difference between a and A etc.
So, get each char of the string add or subtract the right amount from each char, and put them back into a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.