Here is my main piece of code:
import java.awt.*; import java.applet.*; import java.awt.event.*; public class MiniMajorProject extends Applet implements KeyListener, ItemListener { TextField OriginalText; String politeForm; boolean isPoliteForm, isPoliteFormpast, PresentisPoliteForm, isPast; int len; Checkbox checkbox1, checkbox2; PoliteForm politeObject = new PoliteForm(); public void init() { setLayout (null); OriginalText = new TextField(); OriginalText.setBounds(200, 200, 100,35); add(OriginalText); OriginalText.addKeyListener(this); checkbox1 = new Checkbox("polite form present"); checkbox1.setBounds(350,180,130,35); checkbox1.addItemListener(this); add(checkbox1); checkbox2 = new Checkbox("polite form past"); checkbox2.setBounds(350,250,130,35); checkbox2.addItemListener(this); add(checkbox2); } public void itemStateChanged(ItemEvent e) { if (e.getSource() == checkbox1) { len = politeForm.length(); politeObject.polite(); } if (e.getSource() == checkbox2){ if (politeForm.endsWith("iru")){ len = politeForm.length(); isPast = true; isPoliteForm = false; } if (politeForm.endsWith("eru")){ len = politeForm.length(); isPast = true; isPoliteForm = false; } } } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { politeForm = OriginalText.getText(); } this.repaint(); //request a repaint }//end KeyPressed() public void paint(Graphics g) { if (isPoliteForm) { g.drawString(politeForm.substring(0,(len -2)) + "masu", 250,300); } if (isPast) { g.drawString(politeForm.substring(0,(len -2)) + "mashita", 300,300); } }//end paint() public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }//end class
Here is the class PoliteForm:
import java.awt.*; import java.applet.*; import java.awt.event.*; public class PoliteForm { String politeForm; TextField OriginalText; boolean isPoliteForm, isPoliteFormpast, PresentisPoliteForm, isPast; int len; public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { politeForm = OriginalText.getText(); } } public boolean polite(){ if (politeForm.endsWith("iru")){ len = politeForm.length(); isPoliteForm = true; isPast = false; } if (politeForm.endsWith("eru")){ len = politeForm.length(); isPoliteForm = true; isPast = false; } return isPoliteForm; } }
I can't use checkbox one as the program errors, I think it's because I wrote the class wrong..
Can anybody help and fix my problem?
Thankyou so much!