-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotones.java
49 lines (42 loc) · 1.13 KB
/
botones.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import javax.swing.*;
import java.awt.event.*;
public class Botones2 extends JFrame implements ActionListener{
private JButton boton1, boton2, boton3;
pirvate JLabel label1;
public Botones2(){
setLayout(null);
boton1 = new JButton("1");
boton1.setBounds(10,100,90,30);
add(boton1);
boton1.addActionListener(this);
boton2 = new JButton("2");
boton2.setBounds(110,100,90,30);
add(boton2);
boton2.addActionListener(this);
boton3 = new JButton("3");
boton3.setBounds(210,100,90,30);
add(boton3);
boton3.addActionListener(this);
label1 = new JLabel("En espera");
label1.setBounds(10,10,300,30);
add(label1);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == boton1){
label1.setText("Has presionado el Boton 1");
}
if(e.getSource() == boton2){
label1.setText("Has presionado el Boton 2");
}
if(e.getSource() == boton3){
label1.setText("Has presionado el Boton 3");
}
}
public static void main(Sting args[]){
Botones2 botones = new Botones2();
botones.setBounds(0,0,350,200);
botones.setVisible(true);
botones.setResizable(false);
botones.setLocationRelativeTo(null);
}
}