Question

I have this problem for a final thats in my book thats i'm stuck on ....

I have this problem for a final thats in my book thats i'm stuck on . Any help would be really appreciated.

Design and code a Swing GUI to translate text that is input in English into Pig Latin. You can assume that the sentence contains no punctuation.
The rules for Pig Latin are as follows:
⦁ For words that begin with consonants, move the leading consonant to the end of the word and add “ay.” For example, “ball” becomes “allbay”; “button” becomes “uttonbay”; and so forth.
⦁ For words that begin with vowels, add “way” to the end of the word. For example, “all” becomes “allway”; “one” becomes “oneway”; and so forth.
To parse any String of words, you can use a StringTokenizer.
You also can use the Scanner class on a String. For example, the following code:
Scanner scan = new Scanner("foo bar zot");
while (scan.hasNext()) {
System.out.println(scan.next());
}
will output
foo
bar
zot
Use a FlowLayout with a JTextArea for the source text and a separate JTextArea for the translated text. Add a JButton with an event to perform the actual translation.
Also provide a JButton which will exit the program

make screen with a 5 x 1 GridLayout:
⦁ The first panel contains the the title “Pig Latin Translator”
⦁ The second panel contains the two headings
⦁ The third panel contain two JTextArea objects. The one on the left is enabled. The one on the right does not accept input
⦁ The fourth panel holds the “Translate” and “Exit” buttons
⦁ The last panel contains an example of a translation from English to Pig Latin.

Feel free to use your own screen design, one which is more pleasing, easier to use, or more interesting. Add colors, but subtle colors are usually preferable to loud ones.

Submit listings for class or classes in your project. Test your program with at least 3 different translations and PrintScreen those results, as well.

This is some sample code he gave us for context . Can't use anything too advance.

/* GridLayoutDemo1.java - Demonstrate GridLayout functionality
 * Author:     Chris Merrill
 * Topic:      Topic 13
 * Project:    Demonstration
 * Problem Statement: Create two GridLayouts, one 3 row by 2 columns, and the other
 *     2 rows by 3 columns.  Add buttons numbered 1 - 6 in each grid
 *
 * Discussion Topics:
 *   * Like the BorderLayout, the JButtons have grown to occupy the entire region
 *   * What happens when the window is resized?  when the Maximize button is clicked?
 *   * Changing the horizontal and vertical gap between regions.
 */

import java.awt.GridLayout ;
import java.awt.event.ActionListener ;
import java.awt.event.ActionEvent ;
import java.awt.event.WindowAdapter ;
import java.awt.event.WindowEvent ;
import java.awt.Color ;
import javax.swing.JFrame ;
import javax.swing.JButton ;

public class GridLayoutDemo1 extends JFrame implements ActionListener {

    // Constants
    private static final String TITLE = "Grid Layout Demo" ;
    private static final int FRAME_WIDTH = 500,
                             FRAME_HEIGHT = 300,
                             HORIZONTAL_GAP = 5,
                             VERTICAL_GAP = 4 ;
     private static final String NAMES[] = {"one", "two", "three", "four",
                                            "five", "six"} ;
     private boolean toggle = true ;
     private GridLayout grid1, grid2 ;

     public GridLayoutDemo1() {


        // Settings for the frame
        setTitle(TITLE) ;
        setSize(FRAME_WIDTH, FRAME_HEIGHT) ;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
        setResizable(true) ;
        setLocationRelativeTo(null) ;
        getContentPane().setBackground(Color.GREEN);    // for the entire frame

        // Create a 2x3 grid with horizontal and vertical gaps
        // Make this the active grid for now
        grid1 = new GridLayout(2, 3, HORIZONTAL_GAP, VERTICAL_GAP) ;
        setLayout(grid1) ;

        // Create the alternate 3x2 grid, no horizontal or vertical gaps
        grid2 = new GridLayout(3, 2) ;

        // Create and add buttons to the content pane
        JButton[] buttons = new JButton[NAMES.length] ;
        for (int i = 0 ; i < NAMES.length ; i++) {
            buttons[i] = new JButton(NAMES[i]) ;
            buttons[i].addActionListener(this) ;
            add(buttons[i]) ;
        }
    }

    // Clicking on any button swaps the active grid to the inactive grid
    public void actionPerformed( ActionEvent e ) {
        if (toggle) {
            setLayout(grid2) ;
        } else {
            setLayout(grid1) ;
        }
        toggle = !toggle ;
        validate() ;
   }

    // main just creates a frame and makes it visible
    public static void main(String[] args) {
        GridLayoutDemo1 frame = new GridLayoutDemo1() ;
        frame.setVisible(true) ;
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

public class PigLatin extends JFrame
{
private JLabel prompt;
private JTextField input;
private JTextArea output;
private int count;

public PigLatin()
{
super( "Pig Latin Generator" );
prompt = new JLabel( "Enter English phrase:" );
input = new JTextField( 30 );
input.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
String s = e.getActionCommand().toString();
StringTokenizer tokens = new StringTokenizer( s );

count = tokens.countTokens();

while ( tokens.hasMoreTokens() ) {
count--;
printLatinWord( tokens.nextToken() );
}
}
}
);

output = new JTextArea( 10, 30 );
output.setEditable( false );

Container c = getContentPane();
c.setLayout( new FlowLayout() );
c.add( prompt );
c.add( input );
c.add( output );

setSize( 500, 150 );
show();
}

private void printLatinWord( String token )
{
char letters[] = token.toCharArray();
StringBuffer schweinLatein = new StringBuffer();

schweinLatein.append( letters, 1, letters.length - 1 ) ;
schweinLatein.append( Character.toLowerCase( letters[ 0 ] ) );
schweinLatein.append( "ay" );

output.append( schweinLatein.toString() + " " );

if ( count == 0 )
output.append( "\n" );
}

public static void main( String args[] )
{
PigLatin app = new PigLatin();

app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}

Add a comment
Know the answer?
Add Answer to:
I have this problem for a final thats in my book thats i'm stuck on ....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please fix and test my code so that all the buttons and function are working in...

    Please fix and test my code so that all the buttons and function are working in the Sudoku. CODE: SudokuLayout.java: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class SudokuLayout extends JFrame{ JTextArea txtArea;//for output JPanel gridPanel,butPanel;//panels for sudoku bord and buttons JButton hint,reset,solve,newPuzzel;//declare buttons JComboBox difficultyBox; SudokuLayout() { setName("Sudoku Bord");//set name of frame // setTitle("Sudoku Bord");//set...

  • Design and code a SWING GUI to translate text entered in English into Pig Latin. You...

    Design and code a SWING GUI to translate text entered in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: For words that begin with consonants, move the leading consonant to the end of the word and add “ay”. Thus, “ball” becomes “allbay”; “button” becomes “uttonbay”; and so forth. For words that begin with vowels, add “way’ to the end of the word. Thus, “all” becomes “allway”; “one”...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

  • I want to make the JText area scrollable.. but my result doesn't work in that way....

    I want to make the JText area scrollable.. but my result doesn't work in that way. help me plz. package m5; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class TextAnalyzer extends JFrame implements ActionListener {    //Initializes component variables for the frame       //For text typing area    JLabel type = new JLabel("Type sentences in the box below.", JLabel.CENTER);    JTextArea txt = new JTextArea(10, 10);    JPanel txt1 = new JPanel();       //For Statistic data...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT