-2

I have a problem with some codes error is

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

    //My Code Is and its want me to write more and pls what should I do ?

    package ilkframe;
            //Kodlar
            //IlkFrame

            import java.awt.BorderLayout;
            import java.awt.EventQueue;
            import javax.swing.JFrame;
            import javax.swing.JPanel;
            import javax.swing.border.EmptyBorder;
            import javax.swing.JLabel;
            import javax.swing.JTextField;
            import javax.swing.JButton;
            import java.awt.event.MouseAdapter;
            import java.awt.event.MouseEvent;           

            public static void main(String[] args) {
            class ilkframe extends JFrame {
                private JPanel contentPane;
                private JTextField txtIsim;
                private JTextField txtSoyisim;

                public void main(String[] args) {
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            try {
                                ilkframe frame = new ilkframe();
                                frame.setVisible(true);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
    /////////////////////////////////////////////////////////
                public ilkframe() {
                    setTitle("Ilk Frame");
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    setBounds(100, 100, 314, 205);
                    contentPane = new JPanel();
                    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                    setContentPane(contentPane);
                    contentPane.setLayout(null);
                    //
                    JLabel lblNewLabel = new JLabel("Isim :");
                    lblNewLabel.setBounds(51, 41, 46, 14);
                    contentPane.add(lblNewLabel);

                    JLabel lblNewLabel_1 = new JLabel("Soyisim :");
                    lblNewLabel_1.setBounds(51, 78, 46, 14);
                    contentPane.add(lblNewLabel_1);

                    txtIsim = new JTextField();
                    txtIsim.setBounds(107, 38, 117, 20);
                    contentPane.add(txtIsim);
                    txtIsim.setColumns(10);
                    //
                    txtSoyisim = new JTextField();
                    txtSoyisim.setBounds(107, 75, 117, 20);
                    contentPane.add(txtSoyisim);
                    txtSoyisim.setColumns(10);
                    //
                    //Button Olayi
                    JButton btnGonder = new JButton("Gonder");
                    btnGonder.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mousePressed(MouseEvent arg0) {
                            //ikinci frame i çagiriyoruz.
                            ikinciframe ikifrm=new ikinciframe();
                            //Isim ve soyismi ikinci framedeki metoda gonderiyoruz.
                            //her ne kadar bir JFrame olarak kullansakta bunun bir sinif oldugunu
                            //unutmamak lazim.
                            ikifrm.gelenlerVeriler(txtIsim.getText(), txtSoyisim.getText());                
                            //Ikinci Jframe gorunur hale getiriyor.
                            ikifrm.setVisible(true);                
                        }
                    });
                    btnGonder.setBounds(135, 106, 89, 23);
                    contentPane.add(btnGonder);
                }
            }

            //ikinci Frame

            class ikinciframe extends JFrame {

                private JPanel contentPane;
                //TextField i global olarak tanimlamak önemli çünkü her yerden
                //erisebiliriz buna.
                private JTextField txtGelenler;


                public void main(String[] args) {
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            try {

                                ikinciframe frame = new ikinciframe();
                                frame.setVisible(true);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }

                public ikinciframe() {
                    setTitle("Ikinci Frame");
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    setBounds(100, 100, 450, 120);
                    contentPane = new JPanel();
                    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                    setContentPane(contentPane);
                    contentPane.setLayout(null);

                    JLabel lblNewLabel = new JLabel("Gelen Veriler : ");
                    lblNewLabel.setBounds(10, 30, 91, 14);
                    lblNewLabel.setSize(100,11);
                    contentPane.add(lblNewLabel);

                    txtGelenler = new JTextField();
                    txtGelenler.setBounds(111, 27, 269, 20);
                    contentPane.add(txtGelenler);
                    txtGelenler.setColumns(10);

                }

                public void gelenlerVeriler(String isim,String soyisim){

                    //Gelen verileri txtGelenlere Aktariyoruz.
                     txtGelenler.setText(isim+" "+soyisim);
                }
            }
        }
//This is the problem hlp me pls the problem is Error: Main method is not static //in class ilkframe.ilkframe, please define the main method as:
 //  public static void main(String[] args)
//help me pls as fast as you can ?
vipin cp
  • 3,263
  • 3
  • 30
  • 49
  • 3
    "_Main method is not static in class ilkframe.ilkframe, please define the main method as: public static void main(String[] args)_" the compiler is shouting the solution... – AxelH Nov 07 '17 at 11:10
  • Am i seeing this right: You have a class definition inside a static method that is outside of any class? That is not valid java. – OH GOD SPIDERS Nov 07 '17 at 11:12
  • Possible duplicate of [Main method is not static in class error](https://stackoverflow.com/questions/29314199/main-method-is-not-static-in-class-error) – Vasyl Lyashkevych Nov 07 '17 at 11:21

1 Answers1

1

You have badly defined your mains methods that are correctly place in both classes :

public void main(String[] args) {

And the JVM told you to :

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

Also, you have defined a main method outside of the class

...
import java.awt.event.MouseEvent; 

public static void main(String[] args) {
class ilkframe extends JFrame {

This should not compile at all. Remove that declaration... a method need to be in a class

FYI: this is not an Eclipse error, I would expect a compile error and after that a runtime error. But all from Java, not eclipse.

AxelH
  • 13,858
  • 2
  • 24
  • 52