2014-01-19 4 views
0

나는 코딩시 반 초보자이므로이 문제가 발생합니다.Error : Main 메서드를 Text 클래스에서 찾을 수 없습니다. main 메서드를 다음과 같이 정의하십시오. public static void main (String [] args)

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

어디서 고칠 수 있을지 모르겠다.

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

    } 

} 
+0

가능한 중복 http://stackoverflow.com/questions/19339088/main-method -not-found-even-if-ive-declared-it) – RAS

답변

3

JVM은 무엇이 잘못 되었습니까? 주 방법없이 클래스를 실행할 수 없으므로 하나만 주면됩니다. 첫 번째 장에서 흔히 볼 수있는 자바 책이나 튜토리얼을 살펴보십시오. 예를 들어, here을보십시오.

+0

어디에서 추가 할 수 있습니까? – user2997369

+2

@ user2997369 :이 클래스의 메소드 일 수 있지만 먼저 링크를 읽으십시오. 독서와 공부를해야합니다. –

+0

귀하의 경우 동일한 클래스에 속할 수 있습니다. 그러나 당신은 또한 그것을 다른 곳에 넣을 수 있습니다. – Christian

0

당신은 추가 할 필요가 도움

에 대한 thisthis를 참조 주()와 같은 :

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

} 
0

음, 오류 메시지에서 당신이 main() 방법을 놓친 것은 분명하다 자바 프로그램.

그래서 가능한 해결책은 main() 방법을 정의한 후이

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

    } 

    public static void main(String[] args) 
    { 
     // create object of class Text 
     // now call constructor 
    } 

} 

처럼 main() 메소드를 추가 Text 클래스의 객체를 생성하고 Text() 생성자를 호출한다.

코딩 초보자라고 언급 했으므로 예제에서는 java의 생성자에있는 리소스를 참조 할 수 있습니다.

https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Constructor.html

http://www.flowerbrackets.com/learn-constructor-in-java/

http://www.flowerbrackets.com/java-constructor-example/

([내가 선언 한 경우에도 발견되지 Main 메서드]의
관련 문제