Problem while running program:
java.lang.NoSuchMethodError: main
Exception in thread "main"
My code is:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Plane extends JApplet implements
ActionListener
{

	JTextField input;
	JLabel prompt;
	JButton yesButton,noButton;
	int section, firstClass,economyClass;
	boolean seats[];
	boolean questionPosed= false;
	
	public void main( String args[] )
	{
	prompt = new JLabel ("Please enter 1 for First Class and 2 for Economy Class");
	input = new JTextField(4);
	yesButton= new JButton ("Yes");
	noButton= new JButton ("No");
	
	input.addActionListener(this);
	yesButton.addActionListener(this);
	noButton.addActionListener(this);
	
	Container container = getContentPane();
	container.setLayout (new FlowLayout());
	container.add(prompt);
	container.add(input);
	container.add(yesButton);
	container.add(noButton);
	firstClass = 0;
	economyClass = 5;
	
	seats = new boolean [10];
	for (int i =0; i<seats.length;i++)
	seats[i] = false;
	}
	
	public void actionPerformed(ActionEvent actionEvent)
	{
		if (actionEvent.getSource() == input)
		{
		  section = Integer.parseInt(input.getText());
		  String output = "";
		  questionPosed = false;
		  if (section == 1)
		  {
		  	if (firstClass < 5)
			 {
			  seats[firstClass] = true;
			  output = " first Class .Seat #"+ ++firstClass;
			  }
			else if (firstClass >=5 && economyClass <10)
			{
			output = " first Class is full. Do you want Economy Class?"	;
			questionPosed = true;
			}
			else
				output = " Flight is full. Please try next flight";
			}
			else if (section == 2)
			{
				if(economyClass <10)
				 {
				   seats [economyClass] = true;
					output = "economy Class .Seat #"+ ++economyClass;
			  }
			else if (economyClass ==10 && firstClass <5)
			{
			output = " Economy Class is full. Do you want First Class?"	;
			questionPosed = true;
			}
			else
				output = " Flight is full. Please try next flight";
			}
			else
			 output ="Invalid Input";
			 
			 showStatus (output);
			}
			else if (actionEvent.getSource() == yesButton)
			{
			if (questionPosed)
			{
				if(section==1)
			{ seats[economyClass] = true;
			  showStatus( "economy Class .Seat #"+ ++economyClass);
			 }
			 else
			 {
			  seats[firstClass] = true;
			  showStatus( "First Class .Seat #"+ ++firstClass);
			  }
			  
			  questionPosed = false;
			  }
			  }
			  
			  else if(actionEvent.getSource() == noButton)
			  {
			   	if (questionPosed)
					showStatus("Neat flight leaves in 3 hours");
					 questionPosed = false;
				}
			}
		}

Recommended Answers

All 2 Replies

That's an applet. It doesn't need a main method. How are you trying to run it that you are getting that error?

I changed line 17 to public void init()
When i run it from browser(chrome) i can see the form. but it does not do anything.
i can type section 1 or 2 that's it.
It does not take the value.

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.