Advertisement
Guest User

EjemploDEWTDFRE

a guest
Oct 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. public class EjemploText2 extends JFrame implements ActionListener
  5. {
  6. JButton boton1, boton2;
  7. JLabel label;
  8. JTextField texto;
  9. public EjemploText2()
  10. {
  11. JPanel apanel = (JPanel) this.getContentPane();
  12. apanel.setLayout(null);
  13. apanel.setBackground( new Color (128, 128 , 0));
  14.  
  15. setSize(300, 150);
  16. setTitle("Ejemplo");
  17. setVisible(true);
  18. setDefaultCloseOperation(EXIT_ON_CLOSE);
  19.  
  20. boton1=new JButton("Aceptar");
  21. boton1.setBounds(135, 120, 100,30);
  22. add(boton1);
  23. boton1.addActionListener(this);
  24.  
  25. boton2=new JButton("Cerrar");
  26. boton2.setBounds(135, 250, 100, 30);
  27. add(boton2);
  28. boton2.addActionListener(this);
  29. boton2.setEnabled(true);
  30. label = new JLabel("Numero: ");
  31. label.setBounds(40, 40, 100, 20);
  32. label.setBackground( new Color(200, 20, 255));
  33. label.setVisible(true);
  34. add(label);
  35. texto = new JTextField(20);
  36. texto.setBounds(130, 40, 140, 25);
  37. texto.setBackground(new Color(0, 0, 0));
  38. texto.setForeground(new Color (255, 255, 0));
  39. texto.setVisible(true);
  40. add(texto);
  41. }
  42.  
  43. public void actionPerformed(ActionEvent e)
  44. {
  45. if(e.getSource()==boton1)
  46. {
  47. String num=texto.getText();
  48. int x1=Integer.parseInt(num);
  49. JPanel borrador = (JPanel) this.getContentPane();
  50. JTextField cosa = new JTextField();
  51. borrador.setLayout(null);
  52. borrador.setBackground(new Color(128, 0, 0));
  53. cosa.setBounds(new Rectangle(25, 180, 250, 30));
  54. cosa.setText("El numero es: " + x1);
  55. cosa.setEditable(false);
  56. cosa.setHorizontalAlignment(JTextField.LEFT);
  57. borrador.add(cosa, null);
  58. }
  59. if(e.getSource()==boton2)
  60. {
  61. System.exit(0);
  62. }
  63. }
  64. public static void main(String args[])
  65. {
  66. EjemploText2 ventana1 = new EjemploText2();
  67. ventana1.setBounds(100, 110, 450,350);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement