Easy Problem

Discussion in 'Java' started by John Rainkin, May 9, 2004.

  1. John Rainkin

    John Rainkin Guest

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




    | |
     
    John Rainkin, May 9, 2004
    #1
    1. Advertising

  2. John Rainkin

    Sudsy Guest

    John Rainkin wrote:
    > 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
    > . 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.
     
    Sudsy, May 9, 2004
    #2
    1. Advertising

  3. Not only that, but I have flat out given him the answer too!

    Sudsy wrote:

    > John Rainkin wrote:
    >
    >> 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
    >> . 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.
    >
     
    Christian Bongiorno, May 9, 2004
    #3
  4. John Rainkin

    Roedy Green Guest

    Roedy Green, May 9, 2004
    #4
  5. John Rainkin

    Fahd Shariff Guest

    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..."
     
    Fahd Shariff, May 10, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hazzard
    Replies:
    2
    Views:
    656
    Hazzard
    Apr 6, 2004
  2. Kai Henry

    Codebehind Problem -> Easy solution...

    Kai Henry, Apr 12, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    294
    Kai Henry
    Apr 12, 2004
  3. Luis Esteban Valencia

    Very Easy Dropdownlist Problem

    Luis Esteban Valencia, Jan 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    391
    Patrice
    Jan 6, 2005
  4. Arsalan

    Easy multi form problem

    Arsalan, Feb 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    360
    Arsalan
    Feb 22, 2006
  5. Bruno Desthuilliers
    Replies:
    5
    Views:
    396
    Bruno Desthuilliers
    Aug 29, 2007
Loading...

Share This Page