Está en la página 1de 2

package jframe2;

import javax.swing.*;
import java.awt.event.*;

/**
*
* @author ISAI
*/
public class jframe2 extends JFrame implements ActionListener {

private JButton boton1, boton2;


private JLabel label1, label2;
private JTextArea area1;
private JScrollPane scroll1;
private JTextField field1;

public jframe2() {
setLayout(null);
boton1 = new JButton("Ingresar");
boton1.setBounds(0, 300, 100, 30);
add(boton1);
boton1.addActionListener (this);

boton2 = new JButton("Borrar");


boton2.setBounds(200, 300, 100, 30);
add(boton2);
boton2.addActionListener (this);

label1 = new JLabel ("Datos:");


label1.setBounds (10,10,100,30);
add(label1);

label2= new JLabel ();


label2.setIcon(new
javax.swing.ImageIcon("C:\\Users\\ISAI\\Downloads\\UniLoyolaLogo.jpeg"));
label2.setBounds (350,50,300,300);
add (label2);

field1 = new JTextField ();


field1.setBounds(120,17,150,20);
add(field1);

area1 = new JTextArea ();

scroll1 = new JScrollPane (area1);


scroll1.setBounds (10,50,300,200);
add(scroll1);
}
public void actionPerformed (ActionEvent e){
if (e.getSource() == boton1){
String t= field1.getText();
area1.append(t+'\n');
field1.setText("");
}
if (e.getSource ()== boton2){
area1.setText ("");
}

}
public static void main ( String args []){
jframe2 f1 = new jframe2 ();
f1.setBounds(0,0,600,400);
f1.setVisible (true);
f1.setLocationRelativeTo(null);
f1.setResizable (false);
}
}

Ejecucion:

También podría gustarte