Codigo fuente de computrachos con fines educativos

2
1. Codigo Fuente de Computrachos con Fines Educativos!!!!!!!!!!!!!!! 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 import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JPasswordField; import javax.swing.JOptionPane; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Login extends JFrame { private JLabel label, label2; private JTextField user; private JPasswordField pass; private JButton boton1; public Login() { super("LOGIN (user: admin pass: 123"); getContentPane().setLayout(null); //CREAR ETIQUETA Y CAMBIAR ATRIBUTOS label=new JLabel("ID DE USUARIO"); label.setForeground(Color.red); label.setFont(new Font("Arial",Font.BOLD,16)); label.setBounds(20,10,150,30); getContentPane().add(label); //CREAR CAMPO DE TEXTO Y COLOCAR EN POSICION user=new JTextField(15); user.setBounds(150,10,150,30); getContentPane().add(user); //CREAR ETIQUETA Y CAMBIAR ATRIBUTOS label2=new JLabel("PASSWORD"); label2.setForeground(Color.red); label2.setFont(new Font("Arial",Font.BOLD,16)); label2.setBounds(20,60,150,30); getContentPane().add(label2); //CREAR CAMPO DE TEXTO Y COLOCAR EN POSICION pass=new JPasswordField(15); pass.setBounds(150,60,150,30); getContentPane().add(pass); //CREAR BOTON Y CAMBIAR ATRIBUTOS boton1 = new JButton ("INGRESAR"); boton1.setForeground(Color.BLUE); boton1.setFont(new Font("Arial",Font.BOLD,18)); boton1.setBounds(150,90,150,30); //AQUI SE AGREGA EL EVENTO DEL BOTON DIRECTAMENTE boton1.addActionListener(new ActionListener()

Transcript of Codigo fuente de computrachos con fines educativos

Page 1: Codigo fuente de computrachos con fines educativos

1.

Codigo Fuente de Computrachos con Fines Educativos!!!!!!!!!!!!!!!

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

import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JPasswordField; import javax.swing.JOptionPane; import java.awt.Color; import java.awt.Font;

import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Login extends JFrame {

private JLabel label, label2; private JTextField user; private JPasswordField pass; private JButton boton1;

public Login() { super("LOGIN (user: admin pass: 123"); getContentPane().setLayout(null);

//CREAR ETIQUETA Y CAMBIAR ATRIBUTOS label=new JLabel("ID DE USUARIO"); label.setForeground(Color.red); label.setFont(new Font("Arial",Font.BOLD,16)); label.setBounds(20,10,150,30); getContentPane().add(label); //CREAR CAMPO DE TEXTO Y COLOCAR EN POSICION user=new JTextField(15); user.setBounds(150,10,150,30); getContentPane().add(user);

//CREAR ETIQUETA Y CAMBIAR ATRIBUTOS label2=new JLabel("PASSWORD"); label2.setForeground(Color.red); label2.setFont(new Font("Arial",Font.BOLD,16)); label2.setBounds(20,60,150,30); getContentPane().add(label2); //CREAR CAMPO DE TEXTO Y COLOCAR EN POSICION pass=new JPasswordField(15); pass.setBounds(150,60,150,30); getContentPane().add(pass);

//CREAR BOTON Y CAMBIAR ATRIBUTOS boton1 = new JButton ("INGRESAR"); boton1.setForeground(Color.BLUE); boton1.setFont(new Font("Arial",Font.BOLD,18)); boton1.setBounds(150,90,150,30); //AQUI SE AGREGA EL EVENTO DEL BOTON DIRECTAMENTE boton1.addActionListener(new ActionListener()

Page 2: Codigo fuente de computrachos con fines educativos

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

{ public void actionPerformed(ActionEvent evento) { if( user.getText().equals("admin") &&

pass.getText().equals("123") ) JOptionPane.showMessageDialog(null,"INGRESO CORRECTO");

else{

if( !user.getText().equals("admin") ) JOptionPane.showMessageDialog(null,"USUARIO

INCORRECTO");

else if( !pass.getText().equals("123") ) JOptionPane.showMessageDialog(null,"PASSWORD

INCORRECTO"); }

} });

getContentPane().add(boton1);

setSize(350,180); setLocation(200,200); setVisible(true);

} public static void main(String[] args) { new Login(); } }

2. Inicia sesión para responder

3. +4