Retorno de nomes (com gráficos)
Publicado por André (última atualização em 11/09/2009)
[ Hits: 4.931 ]
Homepage: http://127.0.0.1
Aplicação criada no NetBeans, usei gráficos. O que ele faz? Este software possui 2 jbuttons, o "Exibir Mensagem" e o "Encerrar", um JtextField e um JLabel.
O JLabel usamos apenas para deixar escrito: "Escreva aqui o seu nome"
O JButton "Exibir Mensagem" exibe o nome digitado (o nome digitado foi ...) e o "Encerrar" obviamente fecha o programa.
import javax.swing.JOptionPane; /* * TelaPrincipal.java * * Created on 6 de Setembro de 2009, 17:01 */ /** * * @author Juninho */ public class TelaPrincipal extends javax.swing.JFrame { /** Creates new form TelaPrincipal */ public TelaPrincipal() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code "> private void initComponents() { txNome = new javax.swing.JTextField(); lbPreencha = new javax.swing.JLabel(); btMensagem = new javax.swing.JButton(); btEncerrar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Usando o NetBeans :)"); lbPreencha.setFont(new java.awt.Font("MS Sans Serif", 1, 11)); lbPreencha.setText("Digite seu nome "); btMensagem.setText("Exibir Mensagem"); btMensagem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btMensagemActionPerformed(evt); } }); btEncerrar.setText("Encerrar"); btEncerrar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btEncerrarActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(txNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 278, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(layout.createSequentialGroup() .add(38, 38, 38) .add(lbPreencha)) .add(layout.createSequentialGroup() .addContainerGap() .add(btMensagem, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 197, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btEncerrar))) .addContainerGap(36, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(lbPreencha) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(txNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btMensagem) .add(btEncerrar)) .addContainerGap(33, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void btEncerrarActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void btMensagemActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JOptionPane.showMessageDialog(null, "O nome digitado foi : "+ txNome.getText(), "Mensagem", JOptionPane.INFORMATION_MESSAGE); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TelaPrincipal().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btEncerrar; private javax.swing.JButton btMensagem; private javax.swing.JLabel lbPreencha; private javax.swing.JTextField txNome; // End of variables declaration }
Nenhum coment�rio foi encontrado.
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Gravação de tela com temporizador
Aplicativo simples para gravar tela
Eu tive esse erro aqui depois de de baixar o HyprLand Ubuntu na versão... (0)
Como fazer boot em img do debian 12.img da web? (11)
Manjaro 25.0 no permite usar crontab (1)