Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Facultad: Ingeniera
Escuela: Computacin
Asignatura: Java.
I. OBJETIVOS
Creacin de un proyecto:
Dado que todo el desarrollo de Java en el programa tiene lugar dentro de los proyectos,
primero se debe crear un proyecto en el que guardar los orgenes y otros archivos del
proyecto.
GUA 6
pg. 1
Seleccione Archivo > Nuevo proyecto. Tambin puede hacer clic en el icono
Nuevo proyecto (New Project) de la barra de herramientas del programa.
GUA 6
pg. 2
GUA 6
pg. 3
GUA 6
pg. 4
Al
agregar
el
contenedor
de
JFrame,
el
programa
abre
el
formulario
PruebaFormulario.java que acaba de crear en una ficha del Editor con una barra de
herramientas que incluye varios botones, como muestra la ilustracin anterior. El
formulario de PruebaFormulario se abre en la vista Diseo del generador de interfaces
grficas de usuario y aparecen automticamente tres ventanas adicionales en las
esquinas del programa, que permiten navegar, organizar y editar los formularios de la
interfaz grfica de usuario a medida que los genera.
Las diferentes ventanas del generador de interfaces grficas de usuario incluyen:
GUA 6
pg. 5
los
componentes
de
JavaBeans,
JFC/Swing
AWT,
as
como
administradores de diseo.
III. PROCEDIMIENTO
Ejercicio No 1.
1. Primeramente crear un proyecto con el nombre de JavaGuia6.
2. Agregar
al
proyecto
un
contenedor
de
JFrame
con
el
nombre
de
GUA 6
pg. 6
Control Propiedad
JFrame Title
JLabel1 font
text
Valor
Mi Primer Formulario
Tahoma 18 Bold
Hola Java Utilizando
Formulario
GUA 6
pg. 7
package holamundo;
/**
*
* @author usuario
*/
public class FormHolaMundo extends javax.swing.JFrame {
/** Creates new form FormHolaMundo */
public FormHolaMundo() {
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.
*/
Generated Code
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormHolaMundo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
Ejercicio No 2.
1. Agregar
al
proyecto
un
contenedor
de
JFrame
con
el
nombre
de
FormCalculadora.java.
GUA 6
pg. 8
Control
JFrame
JLabel1
JLabel2
JLabel3
JLabel4
Propiedad
Eventos
Codigo
title
font
text
font
text
font
text
font
Variable Name
JTextField font
Variable Name
JTextField font
Variable Name
JButton
font
text
actionPerformed
Variable Name
JButton
font
text
actionPerformed
Variable Name
JButton
font
text
actionPerformed
Variable Name
JButton
font
text
actionPerformed
Variable Name
Valor
Formulario Calculadora
Tahoma 18 Bold
Calculadora ..
Tahoma 11 Plain
Primer Operador:
Tahoma 11 Plain
Segundo Operador:
Tahoma 11 Plain
RespuestajLabel4
Tahoma 11 Plain
Operador1TextField1
Tahoma 11 Plain
Operador2TextField2
Tahoma 11 Plain
Suma
Dar clic
SumaButton1
Tahoma 11 Plain
Resta
Dar clic
RestaButton2
Tahoma 11 Plain
Multiplicacion
Dar clic
MultiplicacionButton3
Tahoma 11 Plain
Division
Dar clic
DivisionButton4
GUA 6
pg. 9
package holamundo;
/**
*
* @author usuario
*/
public class FormCalculadora extends javax.swing.JFrame {
/** Creates new form FormCalculadora */
public FormCalculadora() {
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.
*/
GUA 6
pg. 10
Generated Code
private void MultiplicacionButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Double respuesta = ((Double.parseDouble(Operador1TextField1.getText())) *
(Double.parseDouble(Operador2TextField2.getText())));
RespuestajLabel4.setText("La Multiplicacion es de: " + respuesta);
}
private void RestaButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Double respuesta = ((Double.parseDouble(Operador1TextField1.getText())) (Double.parseDouble(Operador2TextField2.getText())));
RespuestajLabel4.setText("La Resta es de: "+ respuesta);
}
private void SumaButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Double respuesta = (double)((Double.parseDouble(Operador1TextField1.getText())) +
Double.parseDouble(Operador2TextField2.getText()));
RespuestajLabel4.setText("La Suma es de: " + respuesta);
}
private void DivisionButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Double respuesta = ((Double.parseDouble(Operador1TextField1.getText())) /
Double.parseDouble(Operador2TextField2.getText()));
RespuestajLabel4.setText("La Division es de: " + respuesta);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormCalculadora().setVisible(true);
}
});
}
GUA 6
pg. 11
Ejercicio No 3.
1. Agregar
al
proyecto
un
contenedor
de
JFrame
con
el
nombre
de
radiobutton.java.
2. Ingresar al JFrame los siguientes elementos como se muestra en la tabla de la
figura 3.
GUA 6
pg. 12
Control
JFrame
JLabel
JRadioButton
Propiedad
Title
text
horizontalAlignment
icon
verifyInputWheFocu
s
Accesibles Name
Eventos
Codigo
TRAILING
cadillac.jpg
quitar opcin
Variable Name
Serialize To
buttonGroup
select
text
actionCommand
label
Accesible Name
actionPerformed
Variable Name
Serialize To
JRadioButton
buttonGroup
select
text
actionCommand
label
Accesible Name
actionPerformed
Variable Name
Serialize To
JRadioButton
buttonGroup
select
text
actionCommand
label
Accesible Name
actionPerformed
Variable Name
Serialize To
JRadioButton
Valor
Uso de Radio Button
buttonGroup
select
text
actionCommand
label
Accesible Name
actionPerformed
Variable Name
Serialize To
lImagen
radiobutton_lImagen
bgGrupo
Colocar Opcin
Cadillac
Cadillac
Cadillac
Cadillac
Dar click
rbcadillac
radiobutton_rbcadillac
bgGrupo
Colocar Opcin
dodge
dodge
dodge
dodge
Dar click
rbdodge
radiobutton_rbdodge
bgGrupo
Colocar Opcin
ferrary
ferrary
ferrary
ferrary
Dar click
rbferrary
radiobutton_rbferrary
bgGrupo
Colocar Opcin
nissan
nissan
nissan
nissan
Dar click
rbnissan
radiobutton_rbnissan
GUA 6
pg. 13
Control
JRadioButton
Propiedad
buttonGroup
select
text
actionCommand
label
Accesible Name
Eventos
Codigo
actionPerformed
ButtonGroup
Variable Name
Serialize To
Variable Name
Serialize To
Valor
bgGrupo
Colocar Opcin
toyota
toyota
toyota
toyota
Dar click
rbtoyota
radiobutton_rbtoyota
bgGrupo
radiobutton_bgGrupo
package holamundo;
/**
*
* @author usuario
*/
public class radiobutton extends javax.swing.JFrame {
/** Creates new form radiobutton */
public radiobutton() {
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.
*/
GUA 6
pg. 14
GUA 6
pg. 15
GUA 6
pg. 16