I am trying to compile this java file and it is giving me an error say : java.lang.nosuchmethodeorror.main

what could be the problem?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class JChangeFont extends JApplet implements ActionListener
{
   JLabel banner = new JLabel("Your Name");
   int fontSize = 18;
   Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
   JButton button1 = new JButton("Press");
   Container con = getContentPane();
   FlowLayout flow = new FlowLayout();
 
   public void init()
   {
      Container con = getContentPane();
      FlowLayout flow = new FlowLayout();
      con.setLayout(flow);
      banner.setFont(theFont);
      con.add(banner);
      con.add(button1);
      button1.addActionListener(this);
   }
 
   public void actionPerformed(ActionEvent e)
   {
     Object source = e.getSource();
     if (source == button1)
      {
        Font newFont = new Font("Helvetica",Font.ITALIC, fontSize +  10);
        banner.setFont(newFont);
 
     }
 
   }
 
 
 
}

I am trying to compile this java file and it is giving me an error say : java.lang.nosuchmethodeorror.main

what could be the problem?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class JChangeFont extends JApplet implements ActionListener
{
   JLabel banner = new JLabel("Your Name");
   int fontSize = 18;
   Font theFont = new Font("TimesRoman",Font.BOLD, fontSize);
   JButton button1 = new JButton("Press");
   Container con = getContentPane();
   FlowLayout flow = new FlowLayout();
 
   public void init()
   {
      Container con = getContentPane();
      FlowLayout flow = new FlowLayout();
      con.setLayout(flow);
      banner.setFont(theFont);
      con.add(banner);
      con.add(button1);
      button1.addActionListener(this);
   }
 
   public void actionPerformed(ActionEvent e)
   {
     Object source = e.getSource();
     if (source == button1)
      {
        Font newFont = new Font("Helvetica",Font.ITALIC, fontSize +  10);
        banner.setFont(newFont);
 
     }
 
   }
 
 
 
}

and if I add this at the end

public static void main(String[]args)
{

JChangeFont applet = new JChangeFont();

Frame window = new Frame("JChangeFont");

window.setVisible(true);
}

}

}

I get several errors for public void main string saying : illegal start of expression

I am completely lost .... please help/

I appreciate it

Is there a reason that your other thread on this wasn't sufficient?
http://www.daniweb.com/forums/thread264550.html

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

actually, Ezzaral is helping, and he is right: the sollution to this problem is mentioned in that other thread.
an applet is not supposed to have a main method, so if you're being bugged for one while running it, you're not running it the way you should be running an applet.
for some reason, your system thinks it's trying to run a standard Java application, instead of an applet

actually, Ezzaral is helping, and he is right: the sollution to this problem is mentioned in that other thread.
an applet is not supposed to have a main method, so if you're being bugged for one while running it, you're not running it the way you should be running an applet.
for some reason, your system thinks it's trying to run a standard Java application, instead of an applet

When I registered to this website, I thought I would be getting some help. But you guys are not helping. I showed the work here and I am just trying to get help with the errors that I am getting when I try to compile the file.

I just don't get what you guys are saying? Java is new to me and I am learning it, I am taking this course online because I cannot attend college. That's why I am asking for help here, and little help. I am even saying guys please do this project for me.

Thanks for your replies though.

Thanks a lot.

one last time:
you are running an applet as a Java application.
if you were not doing that, it wouldn't go looking for a main method.

so, sollution => run your applet as an applet.
this has been suggested to you several times, don't just ask, read the replies and try the suggestions out. you would've finished your work hours (if not days) ago

This is different... and I think I am not bothering anyone by submitting a new thread in my acount here.

If you don't want to help, you don't have to reply to my thread.

thanks

No, it is not different. It is the same error that you inquired about in the other thread. And as far as "bothering anyone", you're violating this clause in the Keep It Organized rule of our forums

Do not flood the forum by posting the same question more than once

Perhaps you should review them before starting more threads for the same issue.

The problem is solved in the other thread you have posted.....Enjoy!!

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.