please help me in my code the error appears and i can`t figure it out.
i used to write a program that will accepts the user input, but only a word then the program will scramble the word that had been inputted by the user and display it on JFrame(WINDOW)
package gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class FieldInputs extends JFrame {
private JLabel wordL, scrambleWordL;
private JTextField wordTF, scrambleWordTF;
private JButton scrambleB, exitB;
private ScrambleTheWordButtonHandler sbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 400;
private static final int HEIGHT = 400;
public FieldInputs(){
//Create the two JLabel
wordL = new JLabel("Enter a Word:",
SwingConstants.RIGHT);
scrambleWordL = new JLabel("Permutations:",
SwingConstants.RIGHT);
//Create the two JTextField
wordTF = new JTextField(10);
scrambleWordTF = new JTextField(10);
//Create Button For Scramble Action
scrambleB = new JButton("Scramble It.!");
sbHandler = new ScrambleTheWordButtonHandler();
scrambleB.addActionListener(cbHandler);
//Create Exit Button for the user Option
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
//Sets the Title for the Program
setTitle("Scramble The Word");
//Sets the Width and heigth of the Window to Display it
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//Method getting the Container
Container pane = getContentPane();
//Sets the Layout of labels and text fields
pane.setLayout(new GridLayout(3, 2));
//Places the components in the Pane
pane.add(wordL);
pane.add(wordTF);
pane.add(scrambleWordL);
pane.add(scrambleWordTF);
pane.add(scrambleB);
pane.add(exitB);
}
private class ScrambleTheWordButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
String word, scrambleWord;
word = (wordTF.getText());
permute("", word);
}
public static void permute(String beginningString, String endingString) {
if (endingString.length() <= 1)
else
for (int i = 0; i < endingString.length(); i++) {
try {
String newString = endingString.substring(0, i) + endingString.substring(i + 1);
permute(beginningString + endingString.charAt(i), newString);
} catch (StringIndexOutOfBoundsException exception) {
exception.printStackTrace();
}
}
scrambleWordTF.setText("" + scrambleWord);
}
private class ExitButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String []args){
FieldInputs rectObject = new FieldInputs();
JOptionPane.showMessageDialog(null, "Welcome To Our Program");
}
}
}
i WANT also to combine this code to have a linked list display for the shuffled word..
package gui;
import java.util.LinkedList;
import javax.swing.JOptionPane;
public class List {
public static void main (String[]args){
LinkedList myList = new LinkedList();
int number = 0;
for(int counter=1; counter<=2; counter++){
myList.add(new Integer(number));
number = number+2;
}
JOptionPane.showMessageDialog(null,
"The values inserted in the list are...");
for(int index=0; index<myList.size(); ++index){
int temp = (Integer)myList.get(index);
JOptionPane.showMessageDialog(null, temp+ ".");
}
JOptionPane.showMessageDialog(null,
"\nThe first items in the list using getFirst() is..."
+myList.getFirst());
JOptionPane.showMessageDialog(null,
"\nThe last item in the list using getLast() is..."
+myList.getLast());
JOptionPane.showMessageDialog(null,
"\nThe first item in the list using peekFirst() is..."
+myList.peekFirst());
JOptionPane.showMessageDialog(null,
"\nThe last item in the list using peekLast() is..."
+myList.peekLast());
JOptionPane.showMessageDialog(null,
"\nThe values in reverse order are...");
for(int index=myList.size()-1; index>=0; index--){
Integer temp=(Integer)myList.get(index);
JOptionPane.showMessageDialog(null, temp+".");
}
JOptionPane.showMessageDialog(null,
"\nRemoving first value..."+myList.removeFirst());
JOptionPane.showMessageDialog(null,
"\nRemoving last value..."+myList.removeLast());
JOptionPane.showMessageDialog(null,
"\nThe first items in the list using getFirst() is..."
+myList.getFirst());
JOptionPane.showMessageDialog(null,
"\nThe last item in the list using getLast() is..."
+myList.getLast());
JOptionPane.showMessageDialog(null,
"\nThe first item in the list using peekFirst() is..."
+myList.peekFirst());
JOptionPane.showMessageDialog(null,
"\nThe last item in the list using peekLast() is..."
+myList.peekLast());
JOptionPane.showMessageDialog(null,
"\nThe item(s) in the list are/is..."
+myList);
JOptionPane.showMessageDialog(null,
"\nRemoving..."+myList.remove());
JOptionPane.showMessageDialog(null,
"Removing..."+myList.pollFirst());
JOptionPane.showMessageDialog(null,
"Getting the value using peekFirst"
+myList.peekFirst());
JOptionPane.showMessageDialog(null,
"Getting the first item using getFirst"
+myList.getFirst());
}
}