Mostrando las entradas con la etiqueta AppFrame. Mostrar todas las entradas
Mostrando las entradas con la etiqueta AppFrame. Mostrar todas las entradas

Abrir una ventana desde otra ventana

Como se puede ver, la ventana
aparece con un borde mínimo y la etiqueta de control que visualiza un mensaje.

package masterdavidjavabasico;

import java.awt.*;
import java.awt.event.*;


public class ventana 
{
    public static void main(String [] args)
    {
       AppFrame f = new AppFrame();

       f.setSize(200, 200);

       f.addWindowListener(new WindowAdapter() { public void
           windowClosing(WindowEvent e) {System.exit(0);}});

       f.show();
    }
}

class AppFrame extends Frame implements ActionListener
{
    Button b1, b2;
    labelWindow window;

    AppFrame()
    {
        setLayout(new FlowLayout());
        b1 = new Button("Visualizar la ventana");
        add(b1);
        b1.addActionListener(this);

        b2 = new Button("Ocultar la ventana");
        add(b2);
        b2.addActionListener(this);

        window = new labelWindow(this);
        window.setSize(300, 200);
        window.setLocation(300, 200);
    }

    public void actionPerformed(ActionEvent event)
    {
        if(event.getSource() == b1){
            window.setVisible(true);
        }
        if(event.getSource() == b2){
            window.setVisible(false);
        }
    }
}

class labelWindow extends Window {
    Label label;

    labelWindow(AppFrame af){
        super(af);
        setLayout(new FlowLayout());
        label = new Label("Hola desde Java!");
        add(label);
    }

    public void paint (Graphics g)
    {
        int width = getSize().width;
        int height = getSize().height;

        g.drawRect(0, 0, --width, --height);
    }
}