“ActionListener Java” Kod odpowiedzi

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');
  }
});
Troubled Tiger

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.");
})
YEP Python

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);  
  }
}
ayaan

Jak utworzyć słuchacza akcji w Javie

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

Java ActionEvent

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

Odpowiedzi podobne do “ActionListener Java”

Pytania podobne do “ActionListener Java”

Więcej pokrewnych odpowiedzi na “ActionListener Java” w Java

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu