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;
}
}
| |
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;
}
}
| |