martes, 14 de julio de 2015
JAVASCRIPT: Crear una Agenda de Direcciones con COOKIES
<SCRIPT LANGUAGE="JavaScript">
var arrRecords = new Array();
var arrCookie = new Array();
var recCount = 0;
var strRecord="";
expireDate = new Date;
expireDate.setDate(expireDate.getDate()+365);
function cookieVal(cookieName) {
thisCookie = document.cookie.split("; ")
for (i = 0; i < thisCookie.length; i++) {
if (cookieName == thisCookie[i].split("=")[0]) {
return thisCookie[i].split("=")[1];
}
}
return 0;
}
function loadCookie() {
if(document.cookie != "") {
if(cookieVal("Records") != ""){
arrRecords = cookieVal("Records").split(",");
}
currentRecord();
}
}
function setRec() {
strRecord = "";
for(i = 0; i < document.frm1.elements.length; i++) {
strRecord = strRecord + document.frm1.elements[i].value + ":";
}
arrRecords[recCount] = strRecord;
document.frm2.add.value = " NEW ";
document.cookie = "Records="+arrRecords+";expires=" + expireDate.toGMTString();
}
function newRec() {
switch (document.frm2.add.value) {
case " NEW " :
varTemp = recCount;
for(i = 0; i < document.frm1.elements.length; i++) {
document.frm1.elements[i].value = ""
}
recCount = arrRecords.length;
document.frm2.add.value = "CANCEL";
break;
case "CANCEL" :
recCount = varTemp;
document.frm2.add.value = " NEW ";
currentRecord();
break;
}
}
function countRecords() {
document.frm2.actual.value = "Record " + (recCount+1)+"; "+arrRecords.length+" saved records";
}
function delRec() {
arrRecords.splice(recCount,1);
navigate("previous");
setRec();
}
function currentRecord() {
if (arrRecords.length != "") {
strRecord = arrRecords[recCount];
currRecord = strRecord.split(":");
for(i = 0; i < document.frm1.elements.length; i++) {
document.frm1.elements[i].value = currRecord[i];
}
}
}
function navigate(control) {
switch (control) {
case "first" :
recCount = 0;
currentRecord();
document.frm2.add.value = " NEW ";
break;
case "last" :
recCount = arrRecords.length - 1;
currentRecord();
document.frm2.add.value = " NEW ";
break;
case "next" :
if (recCount < arrRecords.length - 1) {
recCount = recCount + 1;
currentRecord();
document.frm2.add.value = " NEW ";
}
break;
case "previous" :
if (recCount > 0) {
recCount = recCount - 1;
currentRecord();
}
document.frm2.add.value = " NEW ";
break;
default:
}
}
function pageLoad(){
if (!Array.prototype.splice) {
function array_splice(ind,cnt) {
if (arguments.length == 0) return ind;
if (typeof ind != "number") ind = 0;
if (ind < 0) ind = Math.max(0,this.length + ind);
if (ind > this.length) {
if (arguments.length > 2) ind = this.length;
else return [];
}
if (arguments.length < 2) cnt = this.length-ind;
cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0;
removeArray = this.slice(ind,ind+cnt);
endArray = this.slice(ind+cnt);
this.length = ind;
for (var i = 2; i < arguments.length; i++) {
this[this.length] = arguments[i];
}
for(var i = 0; i < endArray.length; i++) {
this[this.length] = endArray[i];
}
return removeArray;
}
Array.prototype.splice = array_splice;
}
recCount = 0;
loadCookie();
countRecords();
}
</script>
Colocar dentro del Tag <BODY> ejemplo <Body onLoad="pageLoad()">
Colocar entre el <BODY> y </BODY>
<center>
<form name="frm1">
<table align="center" resize="none" border="0">
<tr>
<td align="right">Name:</td>
<td colspan="5"><input type="box" name="name" size="49"></td>
</tr>
<tr>
<td align="right">Address:</td><td colspan="5"><input type="box" name="address" size="49"></td></tr>
<td align="right">Address 2:</td><td colspan="5" align="left"><input type="box" name="address2" size="49"></td>
</tr>
<tr>
<td align="right">City:</td>
<td><input type="box" name="city" size="15"></td>
<td>State:</td><td><input type="box" name="state" size="15"></td>
<td>Zip:</td><td><input type="box" size="6" name="zip"></td>
</tr>
<tr>
<td align="right">Phone:</td>
<td align="left"><input type="box" name="phone" size="15"></td>
<td align="right">Fax:</td><td align="left"><input type="box" name="fax" size="15"></td>
</tr>
<tr>
<td align="right">Web Page:<td colspan="5" align="left"><input type="box" name="address" size="49"></td>
</tr>
<tr>
<td align="right">E-Mail:<td colspan="5" align="left"><input type="box" name="email" size="49"></td>
</tr>
<tr>
<td align="right" valign="top">Comments:</td>
<td colspan="5" align="left"><input type="box" name="comment1" size="49"><br>
<input type="box" name="comment2" size="49"><br>
<input type="box" name="comment3" size="49"><br>
<input type="box" name="comment4" size="49"><br>
<input type="box" name="comment5" size="49">
</td>
</tr>
</table>
</form>
<form name="frm2">
<table align="center" border="1" resize="none">
<tr>
<td align="center">
<input type="button" name="first" value="|<< " onClick="navigate('first');countRecords()">
<input type="button" name="previous" value=" < " onClick="navigate('previous');countRecords()">
<input type="button" name="next" value=" > " onClick="navigate('next');countRecords()">
<input type="button" name="last" value=" >>|" onClick="navigate('last');countRecords()">
<input type="box" name="actual" size=30>
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="add" value=" NEW " onClick="newRec();countRecords()">
<input type="button" name="set" value="SAVE RECORD" onClick="setRec();countRecords()">
<input type="button" name="del" value="Delete" onClick="delRec();countRecords()">
</td>
</tr>
</table>
</form>
</center>
HTML: Buen Script si quieres poner un Color de Fondo Degradado a tu Página
Código:
style="filter:progid:DXImageTransform.Microsoft.Gradient( endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"
Ejemplo:
<body style="filter:progid:DXImageTransform.Microsoft.Gradient( endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');" >
Calculadora en Consola C# (C Sharp)
{
class examen
{
static void Main(string[] args)
{
Console.Title = "Calculadora";
Console.SetCursorPosition(55, 5);
Console.Write(" : Negro");
Console.SetCursorPosition(55, 6);
Console.Write(" : Blanco");
Console.SetCursorPosition(55, 7);
Console.Write(" : Amarillo");
Console.SetCursorPosition(55, 8);
Console.Write(" : Rojo");
Console.SetCursorPosition(55, 9);
Console.Write(" : Verde");
fondo();
Console.SetCursorPosition(55, 20);
Console.Write("/1/ : Muy pequeño");
Console.SetCursorPosition(55, 21);
Console.Write("/2/ : Pequeño");
Console.SetCursorPosition(55, 22);
Console.Write("/3/ : Normal");
Console.SetCursorPosition(55, 23);
Console.Write("/4/ : Mediano");
Console.SetCursorPosition(55, 24);
Console.Write("/5/ : Grande");
tamaño();
Console.SetCursorPosition(3, 2);
int a = ingreso();
Console.SetCursorPosition(3, 3);
int b = ingreso();
Console.SetCursorPosition(55, 2);
Console.Write("(+) : suma");
Console.SetCursorPosition(55, 4);
Console.Write("(-) : resta");
Console.SetCursorPosition(55, 6);
Console.Write("(*) : multiplicacion");
Console.SetCursorPosition(55, 8);
Console.Write("(/) : division");
Console.SetCursorPosition(3, 5);
Console.Write("===========================");
Console.SetCursorPosition(3, 11);
Console.Write("===========================");
Console.SetCursorPosition(3,6);
Console.Write("operacion");
operaciones(a, b);
Console.ReadKey();
}
static int ingreso()
{
Console.Write("Ingrese el numero--> ");
int n = Int16.Parse(Console.ReadLine());
return n;
}
static void operaciones(int x, int y)
{
Console.SetCursorPosition(25, 6);
string z = Console.ReadLine();
switch (z)
{
case "+":
Console.SetCursorPosition(25, 9);
Console.Write("{0}", x + y);
resultado();
break;
case "-":
Console.SetCursorPosition(25, 9);
Console.Write("{0}", x - y);
resultado();
break;
case "*":
Console.SetCursorPosition(25, 9);
Console.Write("{0}", x * y);
resultado();
break;
case "/":
Console.SetCursorPosition(25, 9);
Console.Write("{0:0.00}", x / y);
resultado();
break;
default:
Console.Write("Error");
break;
}
}
static void fondo()
{
Console.SetCursorPosition(3, 5);
Console.Write("¡CAMBIA EL COLOR DE FONDO!^^----> ");
char f = char.Parse(Console.ReadLine());
switch (f)
{
case 'N':
Console.BackgroundColor = ConsoleColor.Black;
Console.Clear();
break;
case 'B':
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
break;
case 'A':
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Clear();
break;
case 'R':
Console.BackgroundColor = ConsoleColor.Red;
Console.Clear();
break;
case 'V':
Console.BackgroundColor = ConsoleColor.DarkGreen;
Console.Clear();
break;
default:
Console.Write("Error");
break;
}
}
static void tamaño()
{
Console.SetCursorPosition(3, 18);
Console.Write("¡VAMOS..AGRANDA O ACHICA!^^----> ");
string t = Console.ReadLine();
switch (t)
{
case "1":
Console.SetWindowSize(5,10);
Console.Clear();
break;
case "2":
Console.SetWindowSize(10,20);
Console.Clear();
break;
case "3":
Console.SetWindowSize(15,25);
Console.Clear();
break;
case "4":
Console.SetWindowSize(25,35);
Console.Clear();
break;
case "5":
Console.SetWindowSize(50,59);
Console.Clear();
break;
default:
Console.Write("Error");
break;
}
}
static void resultado()
{
Console.SetCursorPosition(3, 9);
Console.Write("RESULTADO");
int res = Int16.Parse(Console.ReadLine());
}
}
}
lunes, 13 de julio de 2015
C# - Calculadora sencilla usando Metodos
using System.Collections.Generic;
using System.Linq;
using System.Text;
using c = System.Console;
/* Para más códigos visita www.zvipuapica.blogspot.com , KEHACKSOFT */
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
c.Title="Calculadora Sencilla Usando Metodos";
string s=signo();
int n1=ingreso();/*Igualamos el valor que toma
el método Ingreso() y lo asignamos a Una variable n1*/
int n2 = ingreso();/*Igualamos el valor que toma
el método Ingreso() y lo asignamos a Una variable n2*/
operacion(n1,n2,s);
denuevo();
c.ReadKey();
}
static int ingreso()
{
c.WriteLine("Ingresa un Numero");
int num = int.Parse(c.ReadLine());
return num;/*devolvemos el valor leido desde consola al metodo.
*/
}
static string signo()
{
c.WriteLine("Ingresa Una Operacion: + - * /");
string d=c.ReadLine();
return d;
}
static void operacion(int a, int b, string t)
{
switch (t)
{
case "+":
c.WriteLine("El resultado es: {0}", a + b);
break;
case "-":
c.WriteLine("El resultado es: {0}", a - b);
break;
case "*":
c.WriteLine("El resultado es: {0}", a * b);
break;
case "/":
c.WriteLine("El resultado es: {0}", a / b);
break;
default:
c.WriteLine(" ");
c.WriteLine(" ");
c.Write("¡¡¡Error!!!");
c.WriteLine(" ");
c.WriteLine(" ");
break;
}
}
static void denuevo()
{
c.WriteLine(" ");
c.WriteLine(" ");
c.WriteLine("Desea Hacer Otra Operacion: 1=Si 2=No");
string rsp=c.ReadLine();
if (rsp == "1")
{
Main();
}
else if (rsp != "1" && rsp != "2")
{
c.WriteLine(" ");
c.WriteLine(" ");
c.WriteLine("¡¡Error Introdusca Una opcion valida..!!");
denuevo();
}
else
{
c.WriteLine(" ");
c.WriteLine(" ");
c.WriteLine("Gracias por Usar esta calculadora");
}
}
}
}
C# - Registro de Notas Usando Arrays
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*Para más códigos visita www.zvipuapica.blogspot.com, KEHACKSOFT */
/*using c = System.Console;*/
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Title="Registrando Notas…!";
Console.BackgroundColor=ConsoleColor.Red;
Console.ForegroundColor=ConsoleColor.Yellow;
Console.Clear();
int cont=0; string s=" "; string p=" ";
inicio(ref p, ref s, ref cont);
int[] num=new int[cont];
string[] alumnos=new string[cont];
float[]parcial=new float[cont];
float[]pfinal=new float[cont];
float[]promedio=new float[cont];
string[] estado=new string[cont];
ingreso(ref alumnos, ref parcial, ref pfinal);
promov(ref promedio, ref estado, ref parcial, ref pfinal, ref num);
Console.Clear();
salida(p,s,num,alumnos,parcial,pfinal,promedio,estado);
Console.ReadKey();
}
static void inicio(ref string nd, ref string nc, ref int na)
{
Console.WriteLine("Nombre del Docente");
nd=Console.ReadLine();
Console.WriteLine("Nombre de la Asignatura");
nc=Console.ReadLine();
Console.WriteLine("Número de Alumnos");
na=Int16.Parse(Console.ReadLine());
Console.Clear();
}
static void ingreso(ref string[] h, ref float[]a, ref float[]r)
{
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine("Nombre del Alumno");
h[i] =Console.ReadLine();
Console.WriteLine("Nota del Parcial");
a[i] =float.Parse(Console.ReadLine());
Console.WriteLine("Nota del Parcial Final");
r[i] =float.Parse(Console.ReadLine());
Console.Clear();
}
}
static void promov(ref float[] z, ref string[] x, ref float[] c, ref float[]v, ref int[]b)
{
for (int i=0; i {
b[i]=i+1;
}
for(int i=0; i
z[i]=(c[i]+v[i])/2;
for (int k=0; k
if (z[k]<10 .5="" br=""> x[k]="Desaprobado";
else
x[k]="Aprobado";
}
}
}
static void salida(string a, string s, int[] d, string[] f, float[] g, float[] h, float[] j, string[] k)
{
Console.WriteLine("Nombre del Docente: {0}", a);
Console.WriteLine("Nombre del curso: {0}", s);
Console.SetCursorPosition(0,3);
Console.Write("Numero");
Console.SetCursorPosition(7,3);
Console.Write("Alumno");
Console.SetCursorPosition(32,3);
Console.Write("Parcial");
Console.SetCursorPosition(40,3);
Console.Write("Parcial-Final");
Console.SetCursorPosition(54,3);
Console.Write("Promedio");
Console.SetCursorPosition(65,3);
Console.Write("Estado");
for (int i=0; i
Console.SetCursorPosition(1, i+5);
Console.WriteLine(d[i]);
Console.SetCursorPosition(12, i + 5);
Console.WriteLine(f[i]);
Console.SetCursorPosition(35, i + 5);
Console.WriteLine(g[i]);
Console.SetCursorPosition(46, i + 5);
Console.WriteLine(h[i]);
Console.SetCursorPosition(56, i + 5);
Console.WriteLine(j[i]);
Console.SetCursorPosition(65, i + 5);
Console.WriteLine(k[i]);
}
}
}
}
domingo, 12 de julio de 2015
Estamos de Vuelta!
Proyectos Universitarios de Programación Digital.
Los códigos son totalmente Gratis.
miércoles, 15 de septiembre de 2010
JAVA Netbeans: Area y Perimetro de un Triangulo Isoseles
-->
martes, 14 de septiembre de 2010
JAVA Netbeans: Que tipo de triangulo es solo x sus Lados? y calcular area y perimetro del triangulo Isoseles
He creado 5 clases están enumeradas...!
1.- Work (Main)
package trabajo;
/**
*
* @author KEHACKSOFT
*/
public class work {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ingresodatos ing=new ingresodatos();
ing.ingreso();
triangulo_isoseles obj=new triangulo_isoseles(ing.getladoA(),ing.getladoB(),ing.getladoC());
obj.triangulo();
}
}
2.- IngresaDatos
package trabajo;
import javax.swing.JOptionPane;
/**
*
* @author KEHACKSOFT
*/
public class ingresodatos {
int a,b,c;
void ingreso()
{
c=Integer.parseInt(JOptionPane.showInputDialog("Ingresa LADO C (BASE): ",""));
a=Integer.parseInt(JOptionPane.showInputDialog("Ingresa LADO A: ",""));
b=Integer.parseInt(JOptionPane.showInputDialog("Ingresa LADO B: ",""));
}
public int getladoA()
{
return a;
}
public int getladoB()
{
return b;
}
public int getladoC()
{
return c;
}
}
3.- triangulo_isoseles
package trabajo;
import javax.swing.JOptionPane;
/**
*
* @author kEHCKSOFT
*/
public class triangulo_isoseles {
//public int catetoA,catetoB,
public double a, b, c; // tamaño de los lados
public double A, B, C; // angulos
public double suma;
//MI CONSTRUCTOR
triangulo_isoseles(int LadoA,int LadoB,int LadoC)
{
a=LadoA;
b=LadoB;
c=LadoC;
}
void triangulo()
{
A = Math.acos( (b * b + c * c - a * a) / (2 * b * c)) * 180 / Math.PI;
B = Math.acos( (a * a + c * c - b * b) / (2 * a * c)) * 180 / Math.PI;
C = Math.acos( (a * a + b * b - c * c) / (2 * a * b)) * 180 / Math.PI;
suma = A + B + C;
JOptionPane.showMessageDialog(null,"Los lados son = [ " + a + ", " + b + ", " +c + "]\n "
+ "Los angulos son = [ " + A + ", " + B + ", " +C + "]\n"
+"La suma de sus angulos es = " + suma);
if (A != B && B != C && C != A)
JOptionPane.showMessageDialog(null,"Es un triangulo escaleno");
}
}
}
}
}
}
4.- Area
package trabajo;
import javax.swing.JOptionPane;
/**
*
* @author KEHACKSOFT
*/
public class area {
double area1,base,altura,basetriangulorectangulo,lado;
area(double a, double c)
{
lado=a;
base=c;
}
void trianguloisoseles()
{
basetriangulorectangulo=base/2;//La altura de un triángulo isósceles divide a la base en dos segmentos iguales.
altura=Math.sqrt(Math.pow(lado, 2)-Math.pow(basetriangulorectangulo, 2));
area1=(base*altura)/2;
JOptionPane.showMessageDialog(null,"El area del Triangulo isoseles es: "+area1);
}
}
5.- Perimetro
package trabajo;
import javax.swing.JOptionPane;
/**
*
* @author KEHACKSOFT
*/
public class perimetro {
double lado,base,perimetro1;
perimetro(double a, double c)
{
lado=a;
base=c;
}
void isoseles()
{
perimetro1=(2*lado)+base;
JOptionPane.showMessageDialog(null,"El perímetro del triangulo Isoseles es..."+perimetro1);
}
}
domingo, 12 de septiembre de 2010
JAVA Netbeans: Juego Dado apuesta.... usando Jlist
Primera Clase (Main)
package jlistjava;
/**
* @author harold
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame1 harold = new JFrame1();
harold.show();
}
}
y la otra clase del Formulario que la llamare (JFrame1)
package jlistjava;
import java.util.Random;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
/**
* @author Harold
*/
public class JFrame1 extends javax.swing.JFrame {
//CREANDO MI CONSTRUCTOR
public JFrame1() {
initComponents();
modelo = new DefaultListModel();
LISTA.setModel(modelo);
}
//CODIGO GENERADO AUTOMATICAMENTE
//
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
LISTA = new javax.swing.JList();
jPanel2 = new javax.swing.JPanel();
cmdAnadir = new javax.swing.JButton();
cmdRemover = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("DADO DE APUESTA (K.Harold Choque Kaneko)");
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
LISTA.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
LISTA.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
LISTA.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
LISTAValueChanged(evt);
}
});
jScrollPane1.setViewportView(LISTA);
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()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
cmdAnadir.setText("Añadir");
cmdAnadir.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
cmdAnadir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdAnadirActionPerformed(evt);
}
});
cmdRemover.setText("Remover");
cmdRemover.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
cmdRemover.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdRemoverActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cmdRemover, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(cmdAnadir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(cmdAnadir, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
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()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}//
private void cmdAnadirActionPerformed(java.awt.event.ActionEvent evt) {
ingreso=Integer.parseInt(JOptionPane.showInputDialog("Ingresa tu apuesta",""));
aleatorio();
}
public void aleatorio()
{int num;
Random rand =new Random();
num=rand.nextInt(6);
if(num!=0)
{
switch (num) {
case 1:
jLabel1.setText("Haz ganado un 50% más de tu apuesta: " +(ingreso*1.5));
break;
case 2:
case 3:
case 4:
case 5:
jLabel1.setText("No haz ganado nada");
break;
case 6:
jLabel1.setText("Haz ganado 100% más de tu apuesta: "+(ingreso*2));
break;
}
modelo.addElement(num);
}
else{ aleatorio(); }
}
private void cmdRemoverActionPerformed(java.awt.event.ActionEvent evt) {
if (Seleccion>=0){
modelo.removeElementAt(Seleccion);
}
jLabel1.setText("");
}
private void LISTAValueChanged(javax.swing.event.ListSelectionEvent evt) {
Seleccion = LISTA.getSelectedIndex();
}
/**
* @param args the command line arguments
*/
DefaultListModel modelo ;
String name = "";
int Seleccion = -1;
int ingreso=0;
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JFrame1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JList LISTA;
private javax.swing.JButton cmdAnadir;
private javax.swing.JButton cmdRemover;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
Descarga el Código desde Aqui
domingo, 29 de agosto de 2010
JAVA: Dado el número que identifica al mes (del 1 al 12) imprimir el nombre del mes.
public static void main(String[] args) {
int mes=3;
switch (mes) {
case 1: System.out.println("Enero"); break;
case 2: System.out.println("Febrero"); break;
case 3: System.out.println("Marzo"); break;
case 4: System.out.println("Abril"); break;
case 5: System.out.println("Mayo"); break;
case 6: System.out.println("Junio"); break;
case 7: System.out.println("Julio"); break;
case 8: System.out.println("Agosto"); break;
case 9: System.out.println("Septiembre"); break;
case 10: System.out.println("Octubre"); break;
case 11: System.out.println("Noviembre"); break;
case 12: System.out.println("Diciembre"); break;
default: System.out.println("Este mes no existe"); break;
}
}
}
Programilla Año bisiesto en JAVA
public static void main(String[] args) {
int mes=2;
int año=1992;
int numDias=30;
switch (mes) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numDias = 31;
break;
case 4:
case 6:
case 9:
case 11:
numDias = 30;
break;
case 2:
if ( ((año % 4 == 0) && !(año % 100 == 0)) (año % 400 == 0) )
numDias = 29;
else
numDias = 28;
break;
default:
System.out.println("Este mes no existe");
break;
}
System.out.println("El mes "+mes+" del año "+año+" tiene "+numDias+" días");
}
}
sábado, 22 de mayo de 2010
Ejercicios en Java
Ejercicio 1
Resolver una ecuación de segundo grado y realizar una serie de cálculos con sus soluciones reales, tomando como punto de partida el siguiente código comentado:
Por consola:
Las soluciones son: -0.5657414540893352 y -1.7675918792439982
Solucion mayor: -0.5657414540893352
La exponencial elevada a la solucion mayor vale: 0.5679388899930863
El coseno de la solucion menor vale: -0.19552774420923652
Soluciones redondeadas hasta cuatro decimales: -0.5657 y -1.7676
El arcoseno de la solucion mayor en radianes: -0.601332163575292
El arcoseno de la solucion mayor en grados sexagesimales: -34.453795058334684
A) Dado el siguiente código, averiguar si va a producirse error de compilación.
Si consideras que se produce dicho error, indicar la causa.
Si consideras que la compilación se realiza con éxito, indicar qué se mostrará por consola al ejecutarlo.
B) Si se elimina el modificador static del método mostrarEdad(..), qué modificaciones deben hacerse en el código para que se muestre por consola lo mismo.