Lee y aprende
lunes, 24 de febrero de 2014
domingo, 9 de febrero de 2014
lunes, 25 de noviembre de 2013
Quien invento el WhatsApp
1.-La empresa creadora de la aplicación, WhatsApp Inc. fue fundada por Jan Koum.
2.- Quien había sido anteriormente el director del equipo de operaciones de plataforma de Yahoo y el antiguo jefe del equipo de ingenieros Brian Acton. La compañía tiene su sede en Silicon Valley.
3.-Por otro lado, WhatsApp Inc. ha recibido inversiones por valor de 8 millones de dólares por parte de la empresa Sequoia Capital.
4.-En Marzo de 2013 Whatsapp anunció que la versión para Android, históricamente gratuita, sería de pago por el primer uso.
5.- Sabrás que una de las plataformas más exitosas hasta el momento es WhatsApp, el servicio de mensajería con más de 300 millones de usuarios activos al mes (y creciendo).
2.- Quien había sido anteriormente el director del equipo de operaciones de plataforma de Yahoo y el antiguo jefe del equipo de ingenieros Brian Acton. La compañía tiene su sede en Silicon Valley.
3.-Por otro lado, WhatsApp Inc. ha recibido inversiones por valor de 8 millones de dólares por parte de la empresa Sequoia Capital.
4.-En Marzo de 2013 Whatsapp anunció que la versión para Android, históricamente gratuita, sería de pago por el primer uso.
5.- Sabrás que una de las plataformas más exitosas hasta el momento es WhatsApp, el servicio de mensajería con más de 300 millones de usuarios activos al mes (y creciendo).
DOBLE 'CHECK'
6.- El doble ‘check’. Dos tics de color verde al lado de tu mensaje significan que se ha leído. Pues no, esto es falso. Cuántas discusiones de pareja se hubieran podido evitar si la empresa de la aplicación hubiera hecho el comunicado antes.sábado, 16 de noviembre de 2013
Hacer una Agenda en NETBEANS
PASO 1: Se ara una clase, que sera la principal se llamara MySql.
En ella se ara la conexión con una base de datos.
CODIGO:
En ella se ara la conexión con una base de datos.
CODIGO:
MySql.java
private static Connection conn;
public static Connection geConnection(){
try {
String host =
"jdbc:derby://localhost:1527/MiAgenda";
String uName = "TonoHdz";
String uPass =
"averatec";
conn =
DriverManager.getConnection(host,uName,uPass);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error "+e.getMessage());
}
return conn;
}
Paso 2: Se ara un JFrame, para diseñar y agregar codigo.
En mi caso quedo asi:
Enfrente de name, phone, mobile, id, enfrente de cada uno de ellos esta un txtfield solo que el relleno lo puse color gris como el del panel y el borde se lo quite. Para que solo se vieran las letras y no los bordes ni nada de eso.
Este es el codigo del Jframe que en mi caso lo llame contactos.
CODIGO:
contactos.java
public class contactos extends
javax.swing.JFrame {
DefaultTableModel model;
Connection conn;
Statement sent;
/**
* Creates new form contactos
*/
public contactos() {
initComponents();
conn = MySql.geConnection();
Desabilitar();
Llenar();
}
void Desabilitar(){
txtId.setEditable(false);
txtNombre.setEditable(false);
txtEmpresa.setEditable(false);
txtTelCel.setEditable(false);
txtCorreo.setEditable(false);
}
void Limpiar(){
txtId.setText("");
txtNombre.setText("");
txtEmpresa.setText("");
txtTelCel.setText("");
txtCorreo.setText("");
}
void Habilitar(){
txtId.setEditable(true);
txtNombre.setEditable(true);
txtEmpresa.setEditable(true);
txtTelCel.setEditable(true);
txtCorreo.setEditable(true);
txtId.requestFocus();
}
void Llenar(){
try {
conn = MySql.geConnection();
String[]
titulos={"Id","Nombre","Empresa","TelCel","Correo"};
String sql="select * from
APP.CONTACTOS";
model = new DefaultTableModel
(null, titulos);
sent = conn.createStatement();
ResultSet rs =
sent.executeQuery(sql);
String[] fila=new String[5];
while (rs.next()) {
fila[0] =
rs.getString("Id");
fila[1] =
rs.getString("Nombre");
fila[2] =
rs.getString("Empresa");
fila[3] =
rs.getString("TelCel");
fila[4] =
rs.getString("Correo");
model.addRow(fila);
}
jTable1.setModel(model);
} catch (Exception e){
e.printStackTrace();
}
}
Lo anterior va antes del
código que genera el asistente de NetBeans
Programación para los
botones:
*****************************************************************
private void
btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {
Limpiar();
Habilitar();
}
*****************************************************************
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt)
{
try {
String sql = "insert into
app.contactos (id,Nombre,Empresa,TelCel,Correo)"
+"values(?,?,?,?,?)";
PreparedStatement ps =
conn.prepareCall(sql);
ps.setString(1, txtId.getText());
ps.setString(2,
txtNombre.getText());
ps.setString(3,
txtEmpresa.getText());
ps.setString(4,
txtTelCel.getText());
ps.setString(5,
txtCorreo.getText());
int n=ps.executeUpdate();
if (n>0){
JOptionPane.showMessageDialog(null,"Datos Guardados
correctamente");
}
} catch (Exception e){
JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
}
Llenar();
Limpiar();
}
*****************************************************************
private void btnModificarActionPerformed(java.awt.event.ActionEvent evt)
{
try{
String sql="Update
app.contactos set Nombre =?, Empresa=?, Telcel=?, Correo=?"+"where
Id=?";
int fila=jTable1.getSelectedRow();
String dao=(String)
jTable1.getValueAt(fila, 0);
PreparedStatement
ps=conn.prepareStatement(sql);
//ps.setString(1, txtId.getText());
ps.setString(1, txtNombre.getText());
ps.setString(2,
txtEmpresa.getText());
ps.setString(3,
txtTelCel.getText());
ps.setString(4,
txtCorreo.getText());
ps.setString(5, dao);
int n=ps.executeUpdate();
if (n>0){
Limpiar();
Llenar();
JOptionPane.showMessageDialog(null,"Datos Modificados");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
}
}
*****************************************************************
private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt)
{
try{
int fila=jTable1.getSelectedRow();
String sql="delete from
app.contactos where id="+jTable1.getValueAt(fila,0);
sent=conn.createStatement();
int n=sent.executeUpdate(sql);
if (n>0) {
Llenar();
JOptionPane.showMessageDialog(null,"Datos eliminados");
Limpiar();
}
} catch (Exception e){
JOptionPane.showMessageDialog(null,"Error "+e.getMessage());
}
}
*****************************************************************
private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0);
}
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
if (evt.getButton()==1){
int fila=jTable1.getSelectedRow();
try {
Habilitar();
String sql="select * from
app.contactos where id=" + jTable1.getValueAt(fila,0);
sent=conn.createStatement();
ResultSet
rs=sent.executeQuery(sql);
rs.next();
txtId.setText(rs.getString("Id"));
txtNombre.setText(rs.getString("Nombre"));
txtEmpresa.setText(rs.getString("Empresa"));
txtTelCel.setText(rs.getString("Telcel"));
txtCorreo.setText(rs.getString("Correo"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
*****************************************************************
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt)
{
Limpiar();
try {
conn = MySql.geConnection();
String[]
titulos={"Id","Nombre","Empresa","TelCel","Correo"};
String sql="select * from
app.contactos where Nombre like
'"+"%"+jtBuscar.getText()+"%'";
model = new DefaultTableModel
(null, titulos);
sent = conn.createStatement();
ResultSet rs=sent.executeQuery(sql);
String[] fila=new String[5];
while (rs.next()) {
fila[0] =
rs.getString("Id");
fila[1] =
rs.getString("Nombre");
fila[2] =
rs.getString("Empresa");
fila[3] =
rs.getString("TelCel");
fila[4] =
rs.getString("Correo");
model.addRow(fila);
}
jTable1.setModel(model);
jtBuscar.setText("");
} catch (Exception e){
e.printStackTrace();
}
}
LISTO, NUESTRA APLICACIÓN AGENDA ESTA LISTA PARA USARSE.
sábado, 9 de noviembre de 2013
Aplicacion -Calculadora- en NetBeans
Como hacer una calculadora en NetBeans.
Se llevara en tres pasos, diseño, codificación, uso.
Diseño:
Hacer un Jframe y arrastras los botones, diseñar a nuestro gusto en mi caso me quedo asi.
utilice 11 button para los numeros, un button para el borrar C, y cinco button para dividir, sumar, restar, multiplicar, y el igual.
Tambien una label para poner el autor By Sarmiento, y un text field para que aparezca el resultado.
Codificacion
este es el código de toda mi calculadora.
En mi caso a mi paquete le llame jcalculator
Como buen programador sabrás que descartar, y que copiar y pegar en tu programa.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jcalculator;
/**
*
* @author sarmiento
*/
public class JavaCalculator extends javax.swing.JFrame {
private double total1 = 0.0;
private double total2 = 0.0;
private char math_operator;
/**
* Creates new form JavaCalculator
*/
public JavaCalculator() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollBar1 = new javax.swing.JScrollBar();
jColorChooser1 = new javax.swing.JColorChooser();
jColorChooser2 = new javax.swing.JColorChooser();
jColorChooser3 = new javax.swing.JColorChooser();
jColorChooser4 = new javax.swing.JColorChooser();
jColorChooser5 = new javax.swing.JColorChooser();
txtDisplay = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
btnOne = new javax.swing.JButton();
btnTwo = new javax.swing.JButton();
btnThree = new javax.swing.JButton();
btnFour = new javax.swing.JButton();
btnFive = new javax.swing.JButton();
btnSix = new javax.swing.JButton();
btnSeven = new javax.swing.JButton();
btnEight = new javax.swing.JButton();
btnNine = new javax.swing.JButton();
btnZero = new javax.swing.JButton();
bntPoint = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
btnEquals = new javax.swing.JButton();
btnSubtract = new javax.swing.JButton();
btnPlus = new javax.swing.JButton();
btnDivide = new javax.swing.JButton();
btnMultiply = new javax.swing.JButton();
btnDelete = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calculator");
txtDisplay.setForeground(new java.awt.Color(255, 0, 0));
txtDisplay.setCaretColor(new java.awt.Color(255, 255, 51));
txtDisplay.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtDisplayActionPerformed(evt);
}
});
btnOne.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnOne.setForeground(new java.awt.Color(102, 0, 0));
btnOne.setText("1");
btnOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOneActionPerformed(evt);
}
});
btnTwo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnTwo.setForeground(new java.awt.Color(102, 0, 102));
btnTwo.setText("2");
btnTwo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTwoActionPerformed(evt);
}
});
btnThree.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnThree.setForeground(new java.awt.Color(0, 204, 0));
btnThree.setText("3");
btnThree.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnThreeActionPerformed(evt);
}
});
btnFour.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnFour.setForeground(new java.awt.Color(0, 153, 153));
btnFour.setText("4");
btnFour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFourActionPerformed(evt);
}
});
btnFive.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnFive.setForeground(new java.awt.Color(255, 102, 153));
btnFive.setText("5");
btnFive.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFiveActionPerformed(evt);
}
});
btnSix.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnSix.setForeground(new java.awt.Color(0, 204, 204));
btnSix.setText("6");
btnSix.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSixActionPerformed(evt);
}
});
btnSeven.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnSeven.setForeground(new java.awt.Color(255, 102, 0));
btnSeven.setText("7");
btnSeven.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSevenActionPerformed(evt);
}
});
btnEight.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnEight.setForeground(new java.awt.Color(255, 0, 51));
btnEight.setText("8");
btnEight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEightActionPerformed(evt);
}
});
btnNine.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnNine.setText("9");
btnNine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNineActionPerformed(evt);
}
});
btnZero.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnZero.setText("0");
btnZero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnZeroActionPerformed(evt);
}
});
bntPoint.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
bntPoint.setText(".");
bntPoint.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bntPointActionPerformed(evt);
}
});
jPanel2.setForeground(new java.awt.Color(153, 255, 153));
btnEquals.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
btnEquals.setForeground(new java.awt.Color(0, 51, 51));
btnEquals.setText("=");
btnEquals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEqualsActionPerformed(evt);
}
});
btnSubtract.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnSubtract.setText("-");
btnSubtract.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSubtractActionPerformed(evt);
}
});
btnPlus.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnPlus.setText("+");
btnPlus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPlusActionPerformed(evt);
}
});
btnDivide.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnDivide.setText("/");
btnDivide.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDivideActionPerformed(evt);
}
});
btnMultiply.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnMultiply.setText("*");
btnMultiply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMultiplyActionPerformed(evt);
}
});
btnDelete.setFont(new java.awt.Font("Narkisim", 1, 14)); // NOI18N
btnDelete.setForeground(new java.awt.Color(255, 0, 204));
btnDelete.setText("C");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnEquals, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnSubtract, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDivide, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(19, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDivide, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSubtract, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnEquals, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(31, Short.MAX_VALUE))
);
jLabel1.setText("By Sarmiento");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bntPoint, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))
.addGap(39, 39, 39))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, Short.MAX_VALUE)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bntPoint, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
btnOne.getAccessibleContext().setAccessibleDescription("");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(txtDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void btnFourActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnFourText = txtDisplay.getText () + btnFour.getText ();
txtDisplay.setText (btnFourText);
}
private void txtDisplayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnOneActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnOneText = txtDisplay.getText () + btnOne.getText ();
txtDisplay.setText (btnOneText);
}
private void btnTwoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnTwoText = txtDisplay.getText () + btnTwo.getText ();
txtDisplay.setText (btnTwoText);
}
private void btnThreeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnThreeText = txtDisplay.getText () + btnThree.getText ();
txtDisplay.setText (btnThreeText);
}
private void btnFiveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnFiveText = txtDisplay.getText () + btnFive.getText ();
txtDisplay.setText (btnFiveText);
}
private void btnSixActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnSixText = txtDisplay.getText () + btnSix.getText ();
txtDisplay.setText (btnSixText);
}
private void btnSevenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnSevenText = txtDisplay.getText () + btnSeven.getText ();
txtDisplay.setText (btnSevenText);
}
private void btnEightActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnEightText = txtDisplay.getText () + btnEight.getText ();
txtDisplay.setText (btnEightText);
}
private void btnNineActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnNineText = txtDisplay.getText () + btnNine.getText ();
txtDisplay.setText (btnNineText);
}
private void btnZeroActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnZeroText = txtDisplay.getText () + btnZero.getText ();
txtDisplay.setText (btnZeroText);
}
private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnPlus.getText ();
getOperator (button_text);
}
private void getOperator(String btnText) {
math_operator = btnText.charAt (0);
total1 = total1 + Double.parseDouble(txtDisplay.getText());
txtDisplay.setText("");
}
private void btnEqualsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (math_operator)
{
case '+':
total2 = total1 + Double.parseDouble (txtDisplay.getText ());
break;
case '-':
total2 = total1 - Double.parseDouble (txtDisplay.getText ());
break;
case '/':
total2 = total1 / Double.parseDouble (txtDisplay.getText ());
break;
case '*':
total2 = total1 * Double.parseDouble (txtDisplay.getText ());
break;
}
txtDisplay.setText (Double.toString (total2));
total1 = 0;
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
//
total2 = 0;
txtDisplay.setText ("");
}
private void btnSubtractActionPerformed(java.awt.event.ActionEvent evt) {
//TODO add your handling code here:
String button_text = btnSubtract.getText ();
getOperator (button_text);
}
private void btnDivideActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnDivide.getText ();
getOperator (button_text);
}
private void btnMultiplyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnMultiply.getText ();
getOperator (button_text);
}
private void bntPointActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnPointText = txtDisplay.getText () + bntPoint.getText ();
txtDisplay.setText (btnPointText);
}
/**
* @param args the command line arguments
*/
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(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.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 JavaCalculator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bntPoint;
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnDivide;
private javax.swing.JButton btnEight;
private javax.swing.JButton btnEquals;
private javax.swing.JButton btnFive;
private javax.swing.JButton btnFour;
private javax.swing.JButton btnMultiply;
private javax.swing.JButton btnNine;
private javax.swing.JButton btnOne;
private javax.swing.JButton btnPlus;
private javax.swing.JButton btnSeven;
private javax.swing.JButton btnSix;
private javax.swing.JButton btnSubtract;
private javax.swing.JButton btnThree;
private javax.swing.JButton btnTwo;
private javax.swing.JButton btnZero;
private javax.swing.JColorChooser jColorChooser1;
private javax.swing.JColorChooser jColorChooser2;
private javax.swing.JColorChooser jColorChooser3;
private javax.swing.JColorChooser jColorChooser4;
private javax.swing.JColorChooser jColorChooser5;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollBar jScrollBar1;
private javax.swing.JTextField txtDisplay;
// End of variables declaration
}
APLICACIÓN:
Y YA ESTA LISTA NUSTRA APLICACIÓN CALCULADORA.
Se llevara en tres pasos, diseño, codificación, uso.
Diseño:
Hacer un Jframe y arrastras los botones, diseñar a nuestro gusto en mi caso me quedo asi.
utilice 11 button para los numeros, un button para el borrar C, y cinco button para dividir, sumar, restar, multiplicar, y el igual.
Tambien una label para poner el autor By Sarmiento, y un text field para que aparezca el resultado.
Codificacion
este es el código de toda mi calculadora.
En mi caso a mi paquete le llame jcalculator
Como buen programador sabrás que descartar, y que copiar y pegar en tu programa.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jcalculator;
/**
*
* @author sarmiento
*/
public class JavaCalculator extends javax.swing.JFrame {
private double total1 = 0.0;
private double total2 = 0.0;
private char math_operator;
/**
* Creates new form JavaCalculator
*/
public JavaCalculator() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollBar1 = new javax.swing.JScrollBar();
jColorChooser1 = new javax.swing.JColorChooser();
jColorChooser2 = new javax.swing.JColorChooser();
jColorChooser3 = new javax.swing.JColorChooser();
jColorChooser4 = new javax.swing.JColorChooser();
jColorChooser5 = new javax.swing.JColorChooser();
txtDisplay = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
btnOne = new javax.swing.JButton();
btnTwo = new javax.swing.JButton();
btnThree = new javax.swing.JButton();
btnFour = new javax.swing.JButton();
btnFive = new javax.swing.JButton();
btnSix = new javax.swing.JButton();
btnSeven = new javax.swing.JButton();
btnEight = new javax.swing.JButton();
btnNine = new javax.swing.JButton();
btnZero = new javax.swing.JButton();
bntPoint = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
btnEquals = new javax.swing.JButton();
btnSubtract = new javax.swing.JButton();
btnPlus = new javax.swing.JButton();
btnDivide = new javax.swing.JButton();
btnMultiply = new javax.swing.JButton();
btnDelete = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calculator");
txtDisplay.setForeground(new java.awt.Color(255, 0, 0));
txtDisplay.setCaretColor(new java.awt.Color(255, 255, 51));
txtDisplay.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtDisplayActionPerformed(evt);
}
});
btnOne.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnOne.setForeground(new java.awt.Color(102, 0, 0));
btnOne.setText("1");
btnOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOneActionPerformed(evt);
}
});
btnTwo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnTwo.setForeground(new java.awt.Color(102, 0, 102));
btnTwo.setText("2");
btnTwo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTwoActionPerformed(evt);
}
});
btnThree.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnThree.setForeground(new java.awt.Color(0, 204, 0));
btnThree.setText("3");
btnThree.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnThreeActionPerformed(evt);
}
});
btnFour.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnFour.setForeground(new java.awt.Color(0, 153, 153));
btnFour.setText("4");
btnFour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFourActionPerformed(evt);
}
});
btnFive.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnFive.setForeground(new java.awt.Color(255, 102, 153));
btnFive.setText("5");
btnFive.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFiveActionPerformed(evt);
}
});
btnSix.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnSix.setForeground(new java.awt.Color(0, 204, 204));
btnSix.setText("6");
btnSix.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSixActionPerformed(evt);
}
});
btnSeven.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnSeven.setForeground(new java.awt.Color(255, 102, 0));
btnSeven.setText("7");
btnSeven.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSevenActionPerformed(evt);
}
});
btnEight.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnEight.setForeground(new java.awt.Color(255, 0, 51));
btnEight.setText("8");
btnEight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEightActionPerformed(evt);
}
});
btnNine.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnNine.setText("9");
btnNine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNineActionPerformed(evt);
}
});
btnZero.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
btnZero.setText("0");
btnZero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnZeroActionPerformed(evt);
}
});
bntPoint.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
bntPoint.setText(".");
bntPoint.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bntPointActionPerformed(evt);
}
});
jPanel2.setForeground(new java.awt.Color(153, 255, 153));
btnEquals.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
btnEquals.setForeground(new java.awt.Color(0, 51, 51));
btnEquals.setText("=");
btnEquals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEqualsActionPerformed(evt);
}
});
btnSubtract.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnSubtract.setText("-");
btnSubtract.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSubtractActionPerformed(evt);
}
});
btnPlus.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnPlus.setText("+");
btnPlus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPlusActionPerformed(evt);
}
});
btnDivide.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnDivide.setText("/");
btnDivide.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDivideActionPerformed(evt);
}
});
btnMultiply.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnMultiply.setText("*");
btnMultiply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMultiplyActionPerformed(evt);
}
});
btnDelete.setFont(new java.awt.Font("Narkisim", 1, 14)); // NOI18N
btnDelete.setForeground(new java.awt.Color(255, 0, 204));
btnDelete.setText("C");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnEquals, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnSubtract, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDivide, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(19, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDivide, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSubtract, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnEquals, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(31, Short.MAX_VALUE))
);
jLabel1.setText("By Sarmiento");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bntPoint, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))
.addGap(39, 39, 39))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, Short.MAX_VALUE)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bntPoint, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
btnOne.getAccessibleContext().setAccessibleDescription("");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(txtDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void btnFourActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnFourText = txtDisplay.getText () + btnFour.getText ();
txtDisplay.setText (btnFourText);
}
private void txtDisplayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnOneActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnOneText = txtDisplay.getText () + btnOne.getText ();
txtDisplay.setText (btnOneText);
}
private void btnTwoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnTwoText = txtDisplay.getText () + btnTwo.getText ();
txtDisplay.setText (btnTwoText);
}
private void btnThreeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnThreeText = txtDisplay.getText () + btnThree.getText ();
txtDisplay.setText (btnThreeText);
}
private void btnFiveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnFiveText = txtDisplay.getText () + btnFive.getText ();
txtDisplay.setText (btnFiveText);
}
private void btnSixActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnSixText = txtDisplay.getText () + btnSix.getText ();
txtDisplay.setText (btnSixText);
}
private void btnSevenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnSevenText = txtDisplay.getText () + btnSeven.getText ();
txtDisplay.setText (btnSevenText);
}
private void btnEightActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnEightText = txtDisplay.getText () + btnEight.getText ();
txtDisplay.setText (btnEightText);
}
private void btnNineActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnNineText = txtDisplay.getText () + btnNine.getText ();
txtDisplay.setText (btnNineText);
}
private void btnZeroActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnZeroText = txtDisplay.getText () + btnZero.getText ();
txtDisplay.setText (btnZeroText);
}
private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnPlus.getText ();
getOperator (button_text);
}
private void getOperator(String btnText) {
math_operator = btnText.charAt (0);
total1 = total1 + Double.parseDouble(txtDisplay.getText());
txtDisplay.setText("");
}
private void btnEqualsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (math_operator)
{
case '+':
total2 = total1 + Double.parseDouble (txtDisplay.getText ());
break;
case '-':
total2 = total1 - Double.parseDouble (txtDisplay.getText ());
break;
case '/':
total2 = total1 / Double.parseDouble (txtDisplay.getText ());
break;
case '*':
total2 = total1 * Double.parseDouble (txtDisplay.getText ());
break;
}
txtDisplay.setText (Double.toString (total2));
total1 = 0;
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
//
total2 = 0;
txtDisplay.setText ("");
}
private void btnSubtractActionPerformed(java.awt.event.ActionEvent evt) {
//TODO add your handling code here:
String button_text = btnSubtract.getText ();
getOperator (button_text);
}
private void btnDivideActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnDivide.getText ();
getOperator (button_text);
}
private void btnMultiplyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String button_text = btnMultiply.getText ();
getOperator (button_text);
}
private void bntPointActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String btnPointText = txtDisplay.getText () + bntPoint.getText ();
txtDisplay.setText (btnPointText);
}
/**
* @param args the command line arguments
*/
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(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JavaCalculator.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 JavaCalculator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bntPoint;
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnDivide;
private javax.swing.JButton btnEight;
private javax.swing.JButton btnEquals;
private javax.swing.JButton btnFive;
private javax.swing.JButton btnFour;
private javax.swing.JButton btnMultiply;
private javax.swing.JButton btnNine;
private javax.swing.JButton btnOne;
private javax.swing.JButton btnPlus;
private javax.swing.JButton btnSeven;
private javax.swing.JButton btnSix;
private javax.swing.JButton btnSubtract;
private javax.swing.JButton btnThree;
private javax.swing.JButton btnTwo;
private javax.swing.JButton btnZero;
private javax.swing.JColorChooser jColorChooser1;
private javax.swing.JColorChooser jColorChooser2;
private javax.swing.JColorChooser jColorChooser3;
private javax.swing.JColorChooser jColorChooser4;
private javax.swing.JColorChooser jColorChooser5;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollBar jScrollBar1;
private javax.swing.JTextField txtDisplay;
// End of variables declaration
}
APLICACIÓN:
Y YA ESTA LISTA NUSTRA APLICACIÓN CALCULADORA.
Reproducción Asexual y sus distintas formas
Reproducción
Para que cada especie sobreviva es necesario que sus miembros
se reproduzcan, esto quiere decir, que originen nuevos individuos que
sustituyen a los que mueren.
La reproducción es una característica principal de los seres
vivos y se lleva cabo de manera asexual o sexual.
//La reproducción constituye el enlace entre las generaciones
de organismos, mantiene sus niveles poblacionales y prolonga su continuidad genética
a través del tiempo//
Reproducción asexual
En esta solo un progenitor origina a los nuevos organismo, idénticos
a él, porque es una copia exacta de sus genes.
La reproducción asexual se puede llevar a cabo de distintas
formas: fisión binaria, gemación, esporulación, fragmentación, etc.
Fision binaria: Consiste
en la división en dos partes iguales de la celula madre; cada celula que se
produce alcanza en poco tiempo el tamaño adecuado, para volver a dividirse y
asi interminablemente.
//Un ejemplo serian Las bacterias que se reproducen una nueva
generación cada 20 minutos//
Gemación: Consiste
en que dentro de la célula madre se forma una pequeña protuberancia llamada
yema, que contiene ya material genético del núcleo dividido de la célula
original; la protuberancia se desprende para formar un nuevo individuo.
//un ejemplo de esta reproducción seria las levaduras, que se
afecuan por la gemación//
Esporulación:
Cuando las condiciones del medio no son propicias para la vida de algunos
organismos unicelulares o pluricelulares, estos producen esporas, que son células
reproductoras asexuales en vida latente que pueden permanecer en este estado
hasta que las condiciones ambientales sean favorables para su desarrollo.
Fragmentación: Una planta puede fragmentarse y de cada parte
originar un nuevo individuo; a este segundo proceso se le denomina mas comúnmente
reproducción vegetariana y se presenta en plantas superiores.
CARACTERÍSTICAS DE LA REPRODUCCIÓN asexual:
1.- La descendencia genera material genético de un solo
progenitor y por lo tanto no hay variabilidad genética.
2.- No se requiere una pareja, ni un proceso complicado con
estructuras reproductoras especiales.
Suscribirse a:
Entradas (Atom)