Jump to content
Fórum Script Brasil
  • 0

Problema Com Awt E Swing


Renato Penna
 Share

Question

Eu quero fazer com que ao usuário clicar em um ítem do menu, seja colocado o início de um formulário na tela. Mas eu clico no ítem do menu e nada acontece. O que está errado?

O código é este ...

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

public class Frame extends JFrame
{
    private JTextField texto1;
    private JLabel label1;
    private JLabel label;
    
    public Frame()
    {
        super("Cadastro de usuário");
        Object label;
        setLayout( new FlowLayout() );

        JMenuBar barra = new JMenuBar();
        setJMenuBar(barra);
        JMenu opcao1 = new JMenu("Arquivo");
        JMenu novo = new JMenu("Novo Cadastro");
        JMenu editar = new JMenu("Editar Cadastro Corrente");
        barra.add(opcao1);
        opcao1.add(novo);
        opcao1.add(editar);
        
        Acao acao = new Acao();
        novo.addActionListener(acao);

        new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                label1 = new JLabel("Nome");
                add(label1);
                texto1 = new JTextField(10);
                add(texto1);
            }
        };
    }
}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.2k
    • Total Posts
      647.5k
×
×
  • Create New...