user2997369
user2997369

Reputation: 57

Error: Main method not found in class Text, please define the main method as: public static void main(String[] args)

I am a semi beginner at coding and ran into this problem.

Error: Main method not found in class Text, please define the main method as:    public static void main(String[] args).

I just don't know where I would fix it.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Text extends JFrame
 {

   ImageIcon aries = new ImageIcon ("aries.jpg");   
   JPanel jp = new JPanel();
   JLabel jl = new JLabel();
   JTextField jt = new JTextField("Month",30);
   JTextField jt2 = new JTextField("Date",30);
   JButton jb = new JButton("Enter");

   public Text()
   {
          setTitle("Tutorial");
          setVisible(true);
          setSize(400, 200);
          setDefaultCloseOperation(EXIT_ON_CLOSE);

          jp.add(jt);
          jp.add(jt2);

          jt.addActionListener(new ActionListener()
          {
                 public void actionPerformed(ActionEvent e)
                 {
                       String input = jt.getText();
                       jl.setText(input); 
                 }
          });

          jp.add(jb);
          jb.addActionListener(new ActionListener()
          {
                  public void actionPerformed(ActionEvent e)
                  {
                         String input = jt.getText();
                         String input2 = jt2.getText();
                         jl.setText(input);
                         jl.setText(input2);
                         int day = Integer.parseInt(input2);
                            if ((input.equals("Test")) && (input2.equals(day >= 26)))//||(input2.equals("27")))))
                                JOptionPane.showMessageDialog(null, "" , "" ,JOptionPane.PLAIN_MESSAGE,aries);
                  }

          });

          add(jp);

   }

}  

Upvotes: 0

Views: 1807

Answers (2)

ravibagul91
ravibagul91

Reputation: 20755

see this and this for more help

You have to add your main() as:

add(jp);
}
public static void main(String[] args){
//Call constructor
}

}  

Upvotes: 0

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

The JVM is telling you exactly what is wrong: You can't run a class without a main method -- so give it one. Please have a look at any beginning Java book or tutorial since this is stuff usually found in the first chapter. For example, please have a look here.

Upvotes: 3

Related Questions