Should would i turn the following code:

import java.awt.*;
import java.io.*;
import java.util.StringTokenizer;
public class ex74
{
	public static void main(String[] args) throws IOException
	{
		Frame f = new Fram();
		String sent;
		StringTokenizer st;
		BufferedReader br = new
			BufferedReader(new InputStreamReader(System.in));
		System.out.print("Enter a sentence:  ");
		sent = br.readLine();
		sent = sent.toLowerCase();
		st = new StringTokenizer(sent, " ,.?!;");
		while (st.hasMoreTokens())
		{
			plw(st.nextToken());
			System.out.print(' ');
		}
		System.out.println();
	}

	public static void plw(String word)
	{
		int x;
		for (x = 1; x < word.length(); x++)
			System.out.print(word.charAt(x));
		System.out.print(word.charAt(0) + "ay");
	}
}

into a program that uses a from for the input. When they enter the sentance the results end up on the output screen.

Save the sentence that they type in into a String, lets call the String mySentence. Then use

javax.swing.JOptionPane.showMessageDialog(null, mySentence);

and it will display your string in a window.

Here is your code.

import java.awt.*;
import java.io.*;
import java.util.StringTokenizer;
import javax.swing.*;
import java.awt.event.*;

public class ex74 extends JFrame
{
               JButton b1=new JButton("OK");
               JTextField t1=new JTextField("",20);
               String output="";
               public ex74() {
                      super("Simple Program");
                      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      getContentPane().setLayout(new FlowLayout());

                      getContentPane().add(t1);
                      getContentPane().add(b1);

                      b1.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                   output="";
                                String sent;
		StringTokenizer st;
		
		sent = t1.getText();
		sent = sent.toLowerCase();
		st = new StringTokenizer(sent, " ,.?!;");
		while (st.hasMoreTokens())
		{
			plw(st.nextToken());
			output = output + " ";
		}
		javax.swing.JOptionPane.showMessageDialog(null, output);


                             }
                      });
 
                      pack();
                      setVisible(true); 
                }
	public static void main(String[] args) {
		 new ex74();
	}

	public  void plw(String word){
		int x;
		for (x = 1; x < word.length(); x++)
			output = output + "\n"  + word.charAt(x);
		output = output + "\n" + word.charAt(0) + "ay";
	}
}
Be a part of the DaniWeb community

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