Easy Problem

J

John Rainkin

I have a class called PigLatin that is provided. I have two text
areas. One you type in and the other will display the result, when the
button translate is pressed. It is suppose to call to the
PigLatin.class and translate the text in Textarea input to PigLatin
and display the translation in Textarea output How do I call in the
method to the PigLatin class? This is the code I have so far. You can
email me at
(e-mail address removed). Thanks in advance.

//Applet to convert English to Pig Latin
//By Chris Lawson

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

public class SampleTextArea1 extends Applet
{
TextField status;
TextArea input, output;
Button translation;
Label label1, label2;

public void init() {

// Counts how many lines are in the text area
label1 = new Label("A English to Pig Latin conversion program
by Chris Lawson");
add(label1);
status = new TextField("Text area contains 1 newlines",40);
add(status);
input = new TextArea( "Type English here",8,40);
add(input);
label2 = new Label("The Pig Latin translation will appear
below");
add(label2);
output = new TextArea( "Translation appears here",8,40);
add(output);
status.setEditable(false);
output.setEditable(false);
translation = new Button ("Translate");
add(translation);

/**translation add action listiner
This is wear I am suppose to add action to the button
The Pig Latin class file should be used hear when the button
is pressed
When button is pressed is should convert it to Pig Latin
Converts to Pig Latin by using the PigLatin.class file
The code should look something like this

translation.addActionListener( new
ActionListener ()
{
public void actionPerformed ( ActionEvent ae )
{
String s = input.getText();
//this is were it needs to call to the PigLatin. class
input.setText();


}


return result;
);
}


*/



}
// An old focus method that displays the status of the Text Area
public boolean gotFocus( Event evt, Object what ) {
if (evt.target == input) {
status.setText("Type English below");
}
return super.gotFocus( evt, what );
}

public boolean lostFocus( Event evt, Object what ) {

// Have super handle character entry:
boolean result = super.lostFocus( evt, what );

if (evt.target == input) {
// Get string in input textfield:
String s = input.getText();

// Count newlines:
int len = s.length();
int newlines = 0;
for (int i = len; i --> 0; ) {
if (s.charAt(i) == '\n') ++newlines;
}

// Report linecount in output textfield:
status.setText("Text area contains " + newlines + " newlines");
}

return result;
}
}




| |
 
S

Sudsy

John said:
I have a class called PigLatin that is provided. I have two text
areas. One you type in and the other will display the result, when the
button translate is pressed. It is suppose to call to the
PigLatin.class and translate the text in Textarea input to PigLatin
and display the translation in Textarea output How do I call in the
method to the PigLatin class? This is the code I have so far. You can
email me at
(e-mail address removed). Thanks in advance.

If memory serves, this is your second request for homework help.
Don't expect a personal reply when posting to a newgroup. Don't
expect homework help either. It's your assignment, not ours.
 
F

Fahd Shariff

The following hints may help:

In the actionPerformed method create an object of the piglatin class.
This might be done in the following way:
PigLatin pigLatin = new PigLatin() ;

Get the input text:
String s = input.getText() ;

Call pigLatin's translate method. This might be as follows:
String result = pigLatin.translate(s) ;

Set the result in the output area:
output.setText(result) ;

Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking..."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top