/* * Created by Emanuel Boboiu * 22 September 2013 * jdk1.7.0_02 * www.forum.pontes.ro * www.limbalatina.ro */ import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class T9 implements ActionListener { // Constants. private static final String initLabel1 = "Bine ai venit!"; private static final String initLabel2 = "Taste apãsate"; private static final String noMatches="Fãrã potriviri!"; // Variables: private static String numbers=""; private static int numberOfWordsInDictionary=0; private static String[] words; // all the words from text file, each at an index in this array. private static String[] chars = {"", "", "aâãbc", "def", "ghiî", "jkl", "mno", "pqrsº", "tþuv", "wxzy"}; private static String[] foundWords; // an array containing the values returned by getT9 method. private static int curWord=0; // For GUI: private static JFrame f=null; private static JLabel label1 = null; private static JLabel label2 = null; // An array for all 12 Buttons: private static JButton[] b = new JButton[13]; // index 0 will remain empty. // The create gui method: public void tGui() { if(f==null) { int fs = 30; // the font size of the labels. // Variables for size and resize the JFrame and JButtons: int height=60; // the height of the buttons. int width=100; // the width of the buttons. int spacing=10; // the distance between buttons, and between buttons + labels and frame edges. int x=spacing; // the x coordinates for the buttons.. int y=(height*2)+(spacing*3); // the y coordinate for the first row of buttons. int jfHeight=(height*6)+(spacing*7)+(spacing*3)+(spacing/2); // the height of the entire frame. int jfWidth=(width*3)+(spacing*4)+spacing+(spacing/2); // the width of the entire frame. f = new JFrame("T9 Editor by Manu"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(jfWidth, jfHeight); f.setLocation(100,100); f.setLayout(null); // Create 2 labels: label1 = new JLabel(initLabel1); label1.setSize((width*3)+(spacing*2), height); label1.setLocation(spacing, spacing); label1.setFont(new Font("Serif", Font.PLAIN, fs)); f.add(label1); label2 = new JLabel(initLabel2); label2.setSize((width*3)+(spacing*2), height); label2.setLocation(spacing, height+(spacing*2)); label2.setFont(new Font("Serif", Font.PLAIN, fs)); f.add(label2); // Buttons names in an array: String[] bNames = new String[] {"", "1 Despre", "2 AÂÃBC", "3 DEF", "4 GHIÎ", "5 JKL", "6 MNO", "7 PQRSª", "8 TÞUV", "9 WXYZ", "* Schimb", "0 Reset", "# ªterg"}; // Create buttons: for(int i=1; i0&&temp.charAt(temp.length()-1)=='|') { temp = temp.substring(0, temp.length()-1); } else { // No matches found, set a value manually: temp=noMatches; } String[] word; word=temp.split("\\|"); return word; } // For buttons events: @Override public void actionPerformed(ActionEvent ae) { String sAct = ae.getActionCommand(); int act =Integer.parseInt(sAct); if(act==1) { JOptionPane.showMessageDialog(f, "Creat în Java.\nAutor: Emanuel Boboiu.\n22 septembrie 2013\nwww.pontes.ro"); } else if(act==10) { switchWords(); } else if(act==11) { resetAllValues(); } else if(act==12) { // to know that's a backspace: processAfterButtons("backspace"); } else if(act>1&&act<10) { processAfterButtons(""+act); } // The # (backspace) and 0 (reset) button are available only if numbers is not empty: if(numbers.length()>0) { b[11].setEnabled(true); b[12].setEnabled(true); } else { resetAllValues(); } } // end events method implemented by ActionListener. } // end T9 class.