• Lenguaje

    Java usando AWT

  • Descripción

    Clásico ¡Hola mundo!

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
import java.awt.*;
import java.awt.event.*;

public class HolaMundo extends Frame implements ActionListener {

    private static final long serialVersionUID = 1L;
    private Button button;

    public Algoritmo() {
        button = new Button("Procesar");
        setLayout(new BorderLayout());
        Panel panel, subpanel;
        panel = new Panel(new FlowLayout());
        panel.add(button);
        add(panel);
        button.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        javax.swing.JOptionPane.showMessageDialog(this, "!Hola mundo!");
        pack();
    }

    public static void main(String[] args) {
        Algoritmo algoritmo = new Algoritmo();
        algoritmo.pack();
        algoritmo.setLocationRelativeTo(null);
        algoritmo.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        algoritmo.setVisible(true);
    }

}