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());
			
		}

	}

Recommended Answers

All 9 Replies

and what error do you get?

it say`s that JVM Launcher fatal exception occured...

the thruth is it`s my first time to use this gui(window)
i`m only familiar w/ JOptionPane.

@stultuske sir/mr
can u edit my code for me or just help me tryin` to solve what`s wrong on my code..

i appreciate whatever u can do,for helping me in my code..
thanks.

get back soon to see whats ur reply... thanks again..

Can you edit your code and wrap it in code tags to preserve its formatting?
Edit your post, select the code and press the [code] icon above the input box.

it say`s that JVM Launcher fatal exception occured...

Please copy and paste here the full text of the error message.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Please copy and paste here the full text of the error message.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

@NormR1

this is the error message:

java.lang.NoSuchMethodError: main
Exception in thread "main"

-i used ECLIPSE and that error appears in the lower right corner of the window console

Try using the java command to execute your program. It should give a better error message. I don't understand what your IDE does or how it creates the message.

Try using the java command to execute your program. It should give a better error message. I don't understand what your IDE does or how it creates the message.

errors 7 items

Severity and Description Path Resource Location Creation Time ID
----------------------------------------------------------------------------------------
cbHandler cannot be resolved Healed/src/scramblelingWord FieldInputs.java line 39
1315185789109 2
ebHandler cannot be resolved Healed/src/scramblelingWord FieldInputs.java line 44
1315185789109 3
ebHandler cannot be resolved Healed/src/scramblelingWord FieldInputs.java line 45
1315185789109 5
ExitButtonHandler cannot be resolved to a type Healed/src/scramblelingWord FieldInputs.java
line 17 1315185789109 1
ExitButtonHandler cannot be resolved to a type Healed/src/scramblelingWord FieldInputs.java
line 44 1315185789109 4
The method main cannot be declared static; static methods can only be declared in a static or top level type Healed/src/scramblelingWord FieldInputs.java line 113 1315185789125 7
The method permute cannot be declared static; static methods can only be declared in a static or top level type Healed/src/scramblelingWord FieldInputs.java line 85 1315185789125 6
The serializable class FieldInputs does not declare a static final serialVersionUID field of type long Healed/src/scramblelingWord FieldInputs.java
line 8 1315185789093 0


SIR SORRY FOR THIS: i did`nt know how to compile my code on CMD it does`nt work..
and the above error message appears on the lower right window (PROBLEM) of eclipse.

Both classes have main method. How could you have written above code if you do not know that application has only one main (desktop app, not talking code as library inside another project or other possible variations of Java developed applications)???
To compile from command line read this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.