Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
548 views

First, have a look at the code:

package javaapplication1;

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

 class Elem implements ActionListener{

    void perform(){
        JFrame frame = new JFrame();
        JButton button;
        button = new JButton("Button");
        frame.getContentPane().add(button) ;
        frame.setSize(30,300);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        button.addActionListener(this);
     }

    public void actionPerformed(ActionEvent ev){
        button.setText("Clicked");
    }
}

 public class JavaApplication1 {

  public static void main(String[] args) {
   Elem obj = new Elem();
   obj.perform();
  }  
}

I just finished my first event-based java GUI, but I'm not sure where I went wrong. When there was no event handling, the code functioned perfectly.

in Coding Resources by Expert (650 points) | 548 views

Please log in or register to answer this question.

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .