|
392
|
Programación / Java / Enviar correo electrónico
|
en: 4 Mayo 2011, 14:25 pm
|
Hola: Uso el netbeans 7.0. Quiero crear una interfaz visual al igual que hice con Visual C#. El código en C# funciona. ¿Cómo es en Java? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; // No olvidar. using System.Net.Mail; // http://social.msdn.microsoft.com/Forums/es-ES/vcses/thread/af364990-af60-47ee-aa6f-8b621b4d14ba // http://social.msdn.microsoft.com/Forums/es-ES/vcses/thread/6e6a339a-ada5-4502-b603-1838d1d48b1f namespace email { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_enviar_Click(object sender, EventArgs e) { button_enviar.Enabled = false; //La cadena "servidor" es el servidor de correo que enviará tu mensaje. string servidor = textBox_smtp.Text; // Crea el mensaje estableciendo quién lo manda y quién lo recibe. MailMessage mensaje = new MailMessage ( textBox_emisor.Text, textBox_receptor.Text, textBox_asunto.Text, richTextBox_mensajazo.Text); try { // Envía archivo adjunto. Attachment archivo_adjunto = new Attachment (textBox_ruta_buscar_archivo .Text); mensaje.Attachments.Add(archivo_adjunto); } catch (ArgumentException) { // Sin asunto. } //Envía el mensaje. SmtpClient cliente = new SmtpClient (servidor ); cliente.UseDefaultCredentials = false; cliente .Credentials = new System.Net.NetworkCredential(textBox_emisor .Text, textBox_contra .Text); cliente.Port = Convert.ToInt32(textBox_puerto.Text); cliente.Host = textBox_smtp.Text; cliente.EnableSsl = true; //Añade credenciales si el servidor lo requiere. //cliente.Credentials = CredentialCache.DefaultNetworkCredentials; try { cliente.Send(mensaje); } catch (SmtpException) { MessageBox.Show("No haz introducido bien la contraseña. \nNo admite ciertos archivos que puedan contener virus como .exe, etc.\nEl archivo es demasiado grande.", "Aviso:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } button_enviar.Enabled = true; } private void button_buscar_adjunto_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox_ruta_buscar_archivo.Text = openFileDialog1.FileName.ToString(); } } } }
Saludo.
|
|
|
393
|
Programación / Programación C/C++ / Resolver un porblema que no encuentro
|
en: 29 Abril 2011, 12:07 pm
|
Hola: Me falla algo que no se el que. ¿Cuál es el error? private: System::Void button_enviar_Click(System::Object^ sender, System::EventArgs^ e) { toolStripStatusLabel1->Text = " "; button_enviar->Enabled = false; //La cadena "servidor" es el servidor de correo que enviará tu mensaje. String^ servidor = textBox_smtp->Text; // Crea el mensaje estableciendo quién lo manda y quién lo recibe. MailMessage^ mensaje = gcnew MailMessage( textBox_emisor->Text, textBox_receptor->Text, textBox_asunto->Text, richTextBox_mensajazo->Text); /*try {*/ // Envía archivo adjunto. Attachment^ archivo_adjunto = gcnew Attachment(textBox_ruta_buscar_archivo->Text); mensaje->Attachments->Add(archivo_adjunto); //} //catch (ArgumentException) //{ // // Sin asunto. //} //Envía el mensaje. SmtpClient^ cliente = gcnew SmtpClient(servidor); cliente->UseDefaultCredentials = false; cliente->Credentials^ = gcnew NetworkCredential(textBox_emisor->Text, textBox_contra->Text); cliente->Port^ = Convert->ToInt32(textBox_puerto->Text); cliente->Host = textBox_smtp->Text; cliente->EnableSsl = true; //Añade credenciales si el servidor lo requiere. //cliente.Credentials = CredentialCache.DefaultNetworkCredentials; /* try {*/ cliente->Send(mensaje); //} //catch (SmtpException) //{ // MessageBox::Show("No haz introducido bien la contraseña. \nNo admite ciertos archivos que puedan contener virus como .exe, etc.\nEl archivo es demasiado grande.", "Aviso:", // MessageBoxButtons::OK, MessageBoxIcon::Exclamation); //} toolStripStatusLabel1->Text = "Enviado."; button_enviar->Enabled = true; }
Compilación: 1>------ Operación Generar iniciada: proyecto: email_smtp_cpp, configuración: Debug Win32 ------ 1> email_smtp_cpp.cpp 1>c:\users\hunter\documents\visual studio 2010\projects\email_smtp_cpp\email_smtp_cpp\Form1.h(341): error C2059: error de sintaxis : '=' 1>c:\users\hunter\documents\visual studio 2010\projects\email_smtp_cpp\email_smtp_cpp\Form1.h(342): error C2059: error de sintaxis : '=' ========== Generar: 0 correctos, 1 incorrectos, 0 actualizados, 0 omitidos ==========
|
|
|
395
|
Programación / Java / Buscara errores.
|
en: 24 Abril 2011, 08:06 am
|
Hola: No se la causa de estos errores. Main.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mypkg; import java.util.Scanner; import java.util.InputMismatchException; /** * * @author Hunter */ public class Main { /** * @param args the command line arguments */ public static void main (String[] args ) { // TODO code application logic here Scanner lector = new Scanner (System. in); int[] palillos = {7,5,3}; JuegoPalillos juego; jugador[0] = "Jugador 1"; jugador[1] = "Jugador 2"; int turno = 0; int fila; int cuantos; juego = new JuegoPalillos(palillos); do{ System. out. printf(jugador [turno ]+". elige fila"); fila = lector.nextInt(); System. out. printf(jugador [turno ]+". ¿cuántos palillos quieres quitar?"); cuantos = lector.nextInt(); if (juego.quitaPalillos(fila.cuantos)){ turno = (turno + 1) % 2; }else{ System. out. printf("Introduce bien la fila y los palillos"); } }catch (InputMismatchException e){ System. out. printf("por favor introduce un número."); lector.next(); System. out. printf("Se ha producido algún error " + exc. toString()); } }while (!juego.finDeJuego()); System. out. println("El ganador ha sido " + jugador [turno ]); }
JuegoPalillos.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mypkg; /** * * @author Hunter */ public class JuegoPalillos { private FilaPalillos[] filas; public JuegoPalillos(int[] palillos){ filas = new FilaPalillos[palillos.length]; for (int i = 0; i < filas.length; i++){ filas[i] = new FilaPalillos(palillos[i]); } } public boolean quitaPalillos(int fila, int cuantos){ if (fila < 0 || fila >= filas.length) return false; else return filas[fila].quitaPalillos(cuantos); } public boolean finDeJuego(){ for (int i = 0; i < filas.length; ++i){ if(filas[i].cuantosPalillos() != 0) return false; } return true; } for (int i = 0; i < filas.length; i++){ s += i + " " + filas[i] + "\n"; } return s; } }
FilaPalillos.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mypkg; /** * * @author Hunter */ public class FilaPalillos { private int numPalillos; public FilaPalillos(int tamaño){ numPalillos = tamaño; } public boolean quitaPalillos(int cuantos){ if (cuantos > numPalillos){ return false; }else{ numPalillos -= cuantos; return true; } } for (int i=0; i < numPalillos; i++){ s += "|"; } return s; } public void añadePalillos(int cuantos){ numPalillos += cuantos; } public int cuantosPalillos(){ return numPalillos; } }
Quiero solucionar los errores de este programa.
|
|
|
396
|
Programación / .NET (C#, VB.NET, ASP) / Cambiar de Strin g abyte o hexadecimal.
|
en: 23 Abril 2011, 10:40 am
|
Hola: ¿Cómo cambiar una varibla de un byte que en realidad es un String a una variable hexzadecimal? El código de abajo, si te gijas bien, la variable Recibidos es un string, que se almacena en la otra variable llamad byte_recibido. El Switch puse los case "A", pero quiero ponerlo en hexadecimal, por ejemplo: case 0x41 // que el 0x41 de la tabl aASCII es la A mayúscula. ¿Existe esa psosibilidad? byte_recibido = Recibidos; Recibidos = System.Convert.ToString(byte_recibido); byte b = 255; switch (byte_recibido) { // A switch section can have more than one case label. case "A": textBox1.BackColor = Color.Red; break; case "B": textBox2.BackColor = Color.Red; break; case "C": textBox3.BackColor = Color.Red; break; case "D": textBox4.BackColor = Color.Red; break; case "a": textBox1.BackColor = Color.Maroon; break; case "b": textBox2.BackColor = Color.Maroon; break; case "c": textBox3.BackColor = Color.Maroon; break; case "d": textBox4.BackColor = Color.Maroon; break; default: // Ignorar cualquier carácter que no reconozca. break; }
|
|
|
397
|
Programación / Java / No me funciona este programa
|
en: 21 Abril 2011, 13:36 pm
|
Hola: Quiero saber el motivo de que no me funciona el programa. Este es el programa. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mypkg; /** * * @author Hunter */ public class Main { /** * @param args the command line arguments */ public static void main (String[] args ) { // TODO code application logic here Fecha fecha = new Fecha(1, 4, 2005); Hora hora = new Hora(17, 30); Examen programación = new Examen("Programación en Java", "A105", fecha, hora); System. out. println(programación. toString()); programación.setFecha(new Fecha(1, 6, 2005)); programación.setHora(new Hora(9, 0)); System. out. println(programación. toString()); } }
Saludo.
|
|
|
398
|
Informática / Software / Un buen heditor hexadecimal.
|
en: 18 Abril 2011, 21:07 pm
|
Hola: Usaba mucho el heditor hexadecimal para curiosear y modificar archivos binarios, por ejemplo este: www.winhex.com (español). Con el Windows 7 64-Bits da problemas y no han sacado a estas alturas de la vida para los 64 bits. ¿Conocen otras alternativas y que sea muy bueno? Saludo.
|
|
|
399
|
Programación / Java / Lograr hacer esta descripticón.
|
en: 6 Abril 2011, 12:07 pm
|
Hace tiempo me encontré este tipo de cosas en Java.
Diseñar una clase llamada fichero que nos permita: Leer, escribir (al final), buscar, modificar y borrar datos en un fichero.
PENSAR COMO IMPLEMENTAR BORRAR UN REGISTRO DE UN FICHERO.
Pensar en dos formas: a) Trabajar directamente en con el fichero. b) Tener todo en un arraylist en memoria trabajando sobre él, y al final grabar todo en el fichero.
¿Hay ejemplo sobre esto?
Me interesa controlar ficheros en Java.
|
|
|
|
|
|
|