import java.awt.*;

import javax.swing.*;

import java.awt.event.*;
class log extends JFrame 
{
	
	JButton b1=new JButton("ok");
	JPanel panel=new JPanel(new GridLayout(2,2));
	
	public log()
	{
		panel.add(b1);
		add(panel,BorderLayout.CENTER);
		b1.addActionListener(new ActionListener(){
			public void actionperformed(ActionEvent ae){
				JPanel pan=new JPanel();
				JFrame frame1 = new JFrame();
				JButton b2=new JButton("ok");
				pan.add(b2);
				frame1.setVisible(true);
				frame1.add(pan);
				frame1.setSize(250,100);
		
				b2.addActionListener(new ActionListener(){
					public void actionperformed(ActionEvent ae){
						JPanel pan1=new JPanel();
						JFrame frame2 = new JFrame();
						JButton b3=new JButton("ok");
						pan1.add(b3);
						frame2.setVisible(true);
						frame2.add(pan1);
						frame2.setSize(250,100);
			
		
		
					}
				});
			}
		});
	}
            public static void main(String args[])
            {
            	log l=new log();
            	l.setSize(300,100);
            	l.setVisible(true);
            }
	
	
	
}

i use eclipse iam getting 2 erors at
b1.addActionListener(new ActionListener()
b2.addActionListener(new ActionListener()

Recommended Answers

at begining change classname from log to MyLog, to avdiods the conflict with reserved words for some Java Method Name

public void actionPerformed(ActionEvent e) {

create a new class which contains just one TopLayoutCOntainer (JFrame, JDialog...) in type to the main method and inside actionPerformed

 
Jump to Post

Your compile error is because

"ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)"

and you implemented actionperformed(ActionEvent)

(Java is case-sensitive)

Jump to Post

All 7 Replies

the errors are
Exception in thread "main" java.lang.Error: Unresolved compilation problems:

The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)

at begining change classname from log to MyLog, to avdiods the conflict with reserved words for some Java Method Name

public void actionPerformed(ActionEvent e) {

create a new class which contains just one TopLayoutCOntainer (JFrame, JDialog...) in type to the main method and inside actionPerformed

MyLo ml = new MyLog
ml.setVisible(true);// not neccesary for JFrame if contructor contains that

Your compile error is because

"ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)"

and you implemented actionperformed(ActionEvent)

(Java is case-sensitive)

create a new class which contains just one TopLayoutCOntainer (JFrame, JDialog...) in type to the main method and inside actionPerformed


i dont understand what u said sir

are you check

public void actionperformed(ActionEvent ae){

vs

public void actionPerformed(ActionEvent e) {

this one I meant

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

public class MyLog extends JFrame {

    private static final long serialVersionUID = 1L;

    public MyLog() {
        MyGui mg = new MyGui();
    }

    private class MyGui {

        private final JFrame frm;
        private final JPanel panel;
        private final JButton b1;

        public MyGui() {
            b1 = new JButton("ok");
            b1.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent ae) {
                    MyGui mg = new MyGui();
                }
            });
            b1.setPreferredSize(new Dimension(200, 45));
            panel = new JPanel(new BorderLayout());
            panel.add(b1, BorderLayout.SOUTH);
            frm = new JFrame("MyFrame");
            frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frm.setPreferredSize(new Dimension(400, 300));
            frm.add(panel, BorderLayout.CENTER);
            frm.pack();
            frm.setVisible(true);
        }
    }

    public static void main(String args[]) {
        MyLog l = new MyLog();
    }
}
Error in line 17 and 27.

Error: public void actionperformed(ActionEvent ae){
    //code goes here
}

Correction: public void actionPerformed(ActionEvent ae){
    //code goes here
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.