You are on page 1of 2

package jay;

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

public class jay implements ActionListener


{
JFrame f;
JTextField str1,str2 ;
JButton benter;
jay()
{
f=new JFrame("Pig Latin");
str1=new JTextField();
str2=new JTextField();
benter=new JButton("Translate");

str1.setBounds(30,100,280,30);
str2.setBounds(30,150,280,30);
benter.setBounds(110,200,100,40);

f.add(str1);
f.add(str2);
f.add(benter);

f.setLayout(null);
f.setVisible(true);
f.setSize(350,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
//event
benter.addActionListener(this);
}
public static void main(String[] args)
{
new jay();
}

@Override
public void actionPerformed(ActionEvent e)
{
{
if(e.getSource()==benter)
{
String str = str1.getText();
String a = str.substring(0,1);

if(a.charAt(0)=="a".charAt(0)||a.charAt(0)=="e".charAt(0)||
a.charAt(0)=="i".charAt(0)||a.charAt(0)=="o".charAt(0)||a.charAt(0)=="u".charAt(0))
{
str2.setText(str.substring(0,str.length())+"way");

}
else
{
str2.setText(str.substring(1,str.length())+a+"ay");
}
}
}
}
}

You might also like