Grafico en Java

Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 3

import javax.swing.

JOptionPane;

/**
* @author alfredo
*/
public class SaludadorApp extends javax.swing.JFrame {

public SaludadorApp() {
initComponents();
}

/**
* este metodo es llamado desde un constructor.
* no modifiques esta parte
* ya que lo genera el mismo neatbeans.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated
Code">
private void initComponents() {

btnSaludador = new javax.swing.JButton();


txtNombre = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Saludador");

btnSaludador.setText("¡Saludar!");
btnSaludador.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaludadorActionPerformed(evt);
}
});

jLabel1.setText("Escribe un nombre para saludar");

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.
Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(172, 172, 172)
.addComponent(btnSaludador))
.addGroup(layout.createSequentialGroup()
.addGap(70, 70, 70)
.addComponent(txtNombre,
javax.swing.GroupLayout.PREFERRED_SIZE, 266,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(124, 124, 124)
.addComponent(jLabel1)))
.addContainerGap(73, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addComponent(jLabel1)
.addGap(41, 41, 41)
.addComponent(txtNombre,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(btnSaludador)
.addContainerGap(55, Short.MAX_VALUE))
);

pack();
}
// </editor-fold>

private void btnSaludadorActionPerformed(java.awt.event.ActionEvent evt)


{

//Muestra el texto que esta en el textbox


JOptionPane.showMessageDialog(this, "¡Hola
"+txtNombre.getText()+"!");

}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting
code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with
the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName())
;
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SaludadorApp.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SaludadorApp.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SaludadorApp.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SaludadorApp.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SaludadorApp().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton btnSaludador;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField txtNombre;
// End of variables declaration
}

También podría gustarte