import java.applet.*; import java.awt.*; import java.awt.event.*; public class Guessword extends Applet implements ActionListener { char charArr[]; String input; int len; boolean equalFlag = false; private TextField tinput; private TextField[] txtCh = new TextField[15]; Button btnInput, btnCheck; Panel pbtn; Panel ptxt; Panel pinput; Panel pmain; Panel pTitle; Label lblTitle; int count; public void init() { //set layout for applet setLayout(new BorderLayout()); //create character array to hold single letters of the input word charArr = new char[15]; for(int i=0;i<15;i++) charArr[i] = ' '; //initialize array with blank //create label for title with central alignment and font lblTitle = new Label("Guess word game", Label.CENTER); lblTitle.setFont(new Font("TimesRoman", Font.BOLD, 30)); //create title panel and add title label to panel pTitle = new Panel(); pTitle.setLayout(new FlowLayout(FlowLayout.CENTER)); pTitle.add(lblTitle); //create panel for array of text field and set layout ptxt = new Panel(); ptxt.setLayout(new FlowLayout()); //Create array of text fields for(int i = 0; i <15; i++) { txtCh[i] = new TextField(); } //add text array of fields to panel ptxt.add(txtCh[0]); ptxt.add(txtCh[1]); ptxt.add(txtCh[2]); ptxt.add(txtCh[3]); ptxt.add(txtCh[4]); ptxt.add(txtCh[5]); ptxt.add(txtCh[6]); ptxt.add(txtCh[7]); ptxt.add(txtCh[8]); ptxt.add(txtCh[9]); ptxt.add(txtCh[10]); ptxt.add(txtCh[11]); ptxt.add(txtCh[12]); ptxt.add(txtCh[13]); ptxt.add(txtCh[14]); //create panel for input text and set layout pinput = new Panel(); pinput.setLayout(new FlowLayout()); //create input text field and set echo character tinput = new TextField(15); tinput.setEchoChar('*'); //add input text field to panel pinput.add(tinput); //create main panel with grid layout //with two rows and one column pmain=new Panel(); pmain.setLayout(new GridLayout(2,1)); //add text array panel and input text panel to central panel pmain.add(ptxt); pmain.add(pinput); //create button panel and button pbtn = new Panel(); pbtn.setLayout(new FlowLayout()); btnInput = new Button("Input"); // add action listener to input button //to get button click event btnInput.addActionListener(this); //create check button and add both button to panel btnCheck = new Button("Check"); btnCheck.addActionListener(this); pbtn.add(btnInput); pbtn.add(btnCheck); //add all panels to applet add(pTitle, BorderLayout.NORTH); add(pmain, BorderLayout.CENTER); add(pbtn, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { //if user clicks input button //fill array with blank char to reset it if(e.getSource() == btnInput) { for(int i=0;i<15;i++) { charArr[i] = ' '; txtCh[i].setText(""); } count = 0; input = tinput.getText(); //get length of the word len = input.length(); //fill array with a word for(int i = 1; i< len-1; i++) charArr[i] = input.charAt(i); //show first letter txtCh[0].setText(String.valueOf(input.charAt(0))); //show last letter txtCh[len-1].setText(String.valueOf(input.charAt(len-1))); //clear the input text tinput.setText(""); } //if user clicks Check button else if (e.getSource() == btnCheck) { count += 1; //look through the text field array //if it contains a letter that exist in char array //display the letter in the right text field for(int i = 1; i