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

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 :: condensed for loop java 
Java :: Execute method on load alternative 
Java :: print all prime no java 
Java :: POM error: Failure to find org.springframework.boot 
Java :: java inser at index 
Java :: Printing Hexadecimal Code 
Java :: java default access modifier 
Java :: MOST COMPLEX NAME OF CONSUMER 
Java :: java namespaces 
Java :: unirest javafx 
Java :: layout focus from recycleview not from top in fragment inside nestedScrollview in android xml 
Java :: java Least prime factor of numbers till n 
Java :: spigot bukkit self cancelling task timer example repeat times 
Java :: csv file data structure java 
Java :: blast multiple protein files 
Java :: string equlity 
Java :: data structure in java 
Java :: do i have to import files from the same package in java 
Java :: Java Creating HashMap from Other Maps 
Java :: dicom read with java 
Java :: how to enforce xml dtd validation in java 
Java :: Add space to the left and right sides of a cell 
Java :: 8233*4 
Java :: scanner in = new scanner(system.in) meaning in java 
Java :: Designing a HashMap Key 
Java :: a Java-8 stream of batches, 
Java :: convert code python to java 
Java :: Class inheritance and encapsulation 
Java :: login in java with 3 attepmtps 
Java :: java this keyword 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =