Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class EjemploText2 extends JFrame implements ActionListener
- {
- JButton boton1, boton2;
- JLabel label;
- JTextField texto;
- public EjemploText2()
- {
- JPanel apanel = (JPanel) this.getContentPane();
- apanel.setLayout(null);
- apanel.setBackground( new Color (128, 128 , 0));
- setSize(300, 150);
- setTitle("Ejemplo");
- setVisible(true);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- boton1=new JButton("Aceptar");
- boton1.setBounds(135, 120, 100,30);
- add(boton1);
- boton1.addActionListener(this);
- boton2=new JButton("Cerrar");
- boton2.setBounds(135, 250, 100, 30);
- add(boton2);
- boton2.addActionListener(this);
- boton2.setEnabled(true);
- label = new JLabel("Numero: ");
- label.setBounds(40, 40, 100, 20);
- label.setBackground( new Color(200, 20, 255));
- label.setVisible(true);
- add(label);
- texto = new JTextField(20);
- texto.setBounds(130, 40, 140, 25);
- texto.setBackground(new Color(0, 0, 0));
- texto.setForeground(new Color (255, 255, 0));
- texto.setVisible(true);
- add(texto);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==boton1)
- {
- String num=texto.getText();
- int x1=Integer.parseInt(num);
- JPanel borrador = (JPanel) this.getContentPane();
- JTextField cosa = new JTextField();
- borrador.setLayout(null);
- borrador.setBackground(new Color(128, 0, 0));
- cosa.setBounds(new Rectangle(25, 180, 250, 30));
- cosa.setText("El numero es: " + x1);
- cosa.setEditable(false);
- cosa.setHorizontalAlignment(JTextField.LEFT);
- borrador.add(cosa, null);
- }
- if(e.getSource()==boton2)
- {
- System.exit(0);
- }
- }
- public static void main(String args[])
- {
- EjemploText2 ventana1 = new EjemploText2();
- ventana1.setBounds(100, 110, 450,350);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement