Funciones del botón HTML
<script>
function myFunction() {
alert("ALERT");
}
</script>
<button onclick="myFunction">Click</button>
Lava
<script>
function myFunction() {
alert("ALERT");
}
</script>
<button onclick="myFunction">Click</button>
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);
}
}
JButton b = new JButton("push me");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//your actions
}
});