Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

actionListener java

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

/*in main*/
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
			System.out.println('x');
  }
});
Comment

java button actionlistener

import java.awt.event.ActionListener; //For action listener
import javax.swing.*; //For JButton

// Inside of function or method
JButton button = new JButton();
button.addActionListener(e -> {
	System.out.println("Another way of writing an action listener.");
})
Comment

java actionlistener

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

public class JButtonExample
{
  public static void main(String[] args) 
  {
    JFrame frame = new JFrame("ActionListener Example");
    JButton btn = new JButton("Click here");
    btn.setBounds(70,80,100,30);
    //Change button text on click
    btn.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
                      btn.setText("OK");
       }
    });
    frame.add(btn);
    frame.setSize(250,250);
    frame.setLayout(null);
    frame.setVisible(true);  
  }
}
Comment

how to create an action listener in java

button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) 
            {
              
            }
        });
Comment

java actionevent

public void actionPerformed(ActionEvent e) {
  
if(e.getSource()==button)  {
    button.setText("Button Clicked!");
  
}}
Comment

actionlistener java

JButton Button = new JButton();
Button.setSize(300,300);
Button.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) 
    System.out.println(BlockNumber)
  	}
});
Comment

actionlistener java

button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("hello world");
            }
        });
Comment

ActionListener

JButton b1 = new JButton("Some Text");
b1.addActionListener(new ActionListener() {
// The Method
}
// Remember! At The End Type This:
});
Comment

actionlistener jmenuitem in java

public class Main extends JFrame{

  //initialize integer height/width values along with declaring 
  //Swing component variables
  private final int W = 500,
                    H = 500;

  private JMenu file, headMenu, bgMenu;
  private JMenuBar menuBar;
  private JMenuItem exitItem;

  //constructor
  public Main(){
    setTitle("Move the Head");
    setSize(W, H);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);

    initializeElements();

  }

  //Initializes the elements, this part is missing from your code above.
  public void initializeElements(){

    menuBar = new JMenuBar();
    file = new JMenu("File");
    exitItem = new JMenuItem("Exit");

    exitItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ev) {
        System.exit(0);
      }
    });

    headMenu = new JMenu("Heads");
    bgMenu = new JMenu("Backgrounds");

  }

  public static void main( String[] args ) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Main f = new Main();
            f.setVisible(true);
        }
    });
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: spring xml 
Java :: spring data rest format date 
Java :: difference between offer and add in linkedlist in java 
Java :: frequency of number in java using hashmap using getordefault 
Java :: character to lower java 
Java :: android internet permission 
Java :: public static int to String java 
Java :: check java version 
Java :: how to generate output in various colors in java 
Java :: border bottom android xml 
Java :: java int to binary string 
Java :: get block player is looking at bukkit 
Java :: java add listent to button 
Java :: input string a list in java 
Java :: java how to get current time 
Java :: how to get path of captured image in android 
Java :: linked list sorting in java 
Java :: first java program 
Java :: how to reverse a list in java 
Java :: anagram java program 
Java :: java days between two dates 
Java :: spring @Bean destroyMethod 
Java :: font type javafx button css 
Java :: java.lang.NoSuchMethodError: org.apache.logging.log4j.spi.LoggerContextFactory.isClassLoaderDependent()Z after log4j update 
Java :: javafx object rectangle 
Java :: How to perform counting sort in Java? 
Java :: getconstructor java 
Java :: convert int to double with 2 decimal places java 
Java :: prime number between given range in java 
Java :: int to enum java 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =