Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > JAVA
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 16-11-2017
REHome REHome is offline
Miembro
 
Registrado: jul 2003
Ubicación: España
Posts: 454
Poder: 21
REHome Va por buen camino
Abrir y cerrar bandeja de discos con Java

Buenas a todos y a todas:



Quiero pasar este código en consola de C#, VB .net o el C++ CLR a Java, usen Eclipse o NetBeans. Lo que hace el código es si pulsas A o la letra C abre o cierra la bandeja del lector de discos. A parte de C#, también está en C++ CLR y VB .net por si lo entienden mejor. Lo que hace el código es abrir y cerrar la bandeja de discos del lector, sea IDE o SATA.

Código C#:
Código:
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Lector_teclado_consola_cs
{
    class Program
    {
        [DllImport("winmm.dll")]
        public static extern Int32 mciSendString(string lpstrCommand, StringBuilder lpstrReturnString,
        int uReturnLength, IntPtr hwndCallback);

        public static StringBuilder rt = new StringBuilder(127);

        public static void DoEvents()
        {
            // Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
            Console.SetCursorPosition(0, 6);
            Console.Write("Abriendo...");
        }

        public static void DoEvents2()
        {
            // Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
            Console.SetCursorPosition(0, 6);
            Console.Write("Cerrando...");
        }

        static void Main(string[] args)
        {
            // Título de la ventana.
            Console.Title = "Control lector de bandeja. C#";

            // Tamaño ventana consola.
            Console.WindowWidth = 29; // X. Ancho.
            Console.WindowHeight = 8; // Y. Alto. 

            // Cursor invisible.
            Console.CursorVisible = false; 

            // Posición del mansaje en la ventana.
            Console.SetCursorPosition(0, 0);
            Console.Write(@"Control bandeja del lector:

A - Abrir bandeja.
C - Cerrar bandeja.
===========================");



            ConsoleKey key;
            //Console.CursorVisible = false;
            do
            {
                key = Console.ReadKey(true).Key;

                string mensaje = string.Empty;

                //Asignamos la tecla presionada por el usuario
                switch (key)
                {
                    case ConsoleKey.A:
                        // mensaje = "Abriendo..."; 
                        Console.SetCursorPosition(0, 6);
                        DoEvents();
                        mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero);
                        mensaje = "Abierto.";
                        break;

                    case ConsoleKey.C:
                        // mensaje = "Cerrando...";
                        Console.SetCursorPosition(0, 6);
                        DoEvents2();
                        mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero);
                        mensaje = "Cerrado.";
                        break;
                }

                Console.SetCursorPosition(0, 6);
                Console.Write("           ");
                Console.SetCursorPosition(0, 6);
                Console.Write(mensaje);

            }
            while (key != ConsoleKey.Escape);
        }
    }
}
Código VB .net:
Código:
Imports System.Runtime.InteropServices
Imports System.Text

Module Module1
    <DllImport("winmm.dll")>
    Public Function mciSendString(lpstrCommand As String, lpstrReturnString As StringBuilder, uReturnLength As Integer, hwndCallback As IntPtr) As Int32
    End Function

    Public rt As New StringBuilder(127)

    Public Sub DoEvents()
        ' Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
        Console.SetCursorPosition(0, 6)
        Console.Write("Abriendo...")
    End Sub

    Public Sub DoEvents2()
        ' Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
        Console.SetCursorPosition(0, 6)
        Console.Write("Cerrando...")
    End Sub

    Sub Main()
        ' Título de la ventana.
        Console.Title = "Control lector de bandeja. Visual Basic"

        ' Tamaño ventana consola.
        Console.WindowWidth = 29 ' X. Ancho.
        Console.WindowHeight = 8 ' Y. Alto. 
        ' Cursor invisible.
        Console.CursorVisible = False

        ' Posición del mansaje en la ventana.
        Console.SetCursorPosition(0, 0)
        Console.Write("Control bandeja del lector:" & vbCr & vbLf & vbCr & vbLf &
                      "A - Abrir bandeja." & vbCr & vbLf &
                      "C - Cerrar bandeja." & vbCr & vbLf &
                      "===========================")

        Dim key As ConsoleKey
        'Console.CursorVisible = false;
        Do
            key = Console.ReadKey(True).Key

            Dim mensaje As String = String.Empty

            'Asignamos la tecla presionada por el usuario
            Select Case key
                Case ConsoleKey.A
                    ' mensaje = "Abriendo..."; 
                    Console.SetCursorPosition(0, 6)
                    DoEvents()
                    mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero)
                    mensaje = "Abierto."
                    Exit Select

                Case ConsoleKey.C
                    ' mensaje = "Cerrando...";
                    Console.SetCursorPosition(0, 6)
                    DoEvents2()
                    mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero)
                    mensaje = "Cerrado."
                    Exit Select
            End Select

            Console.SetCursorPosition(0, 6)
            Console.Write("           ")
            Console.SetCursorPosition(0, 6)

            Console.Write(mensaje)
        Loop While key <> ConsoleKey.Escape
    End Sub

End Module
Código C++ CLR:
Código:
#include "stdafx.h"

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;

[DllImport("winmm.dll")]
extern Int32 mciSendString(String^ lpstrCommand, StringBuilder^ lpstrReturnString, 
	int uReturnLength, IntPtr hwndCallback);

static void DoEvents()
{
	Console::SetCursorPosition(0, 6);
	Console::Write("Abriendo...");
}

static void DoEvents2()
{
	Console::SetCursorPosition(0, 6);
	Console::Write("Cerrando...");
}

int main(array<System::String ^> ^args)
{
	StringBuilder^ rt = gcnew StringBuilder(127);

	// Título de la ventana.
	Console::Title = "Control lector de bandeja. C++ CLR";

	// Tamaño ventana consola.
	Console::WindowWidth = 29; // X. Ancho.
	Console::WindowHeight = 8; // Y. Alto. 

							  // Cursor invisible.
	Console::CursorVisible = false;

	// Posición del mansaje en la ventana.
	Console::SetCursorPosition(0, 0);
	Console::WriteLine("Control bandeja del lector : \n\n" +
		"A - Abrir bandeja. \n" +
		"C - Cerrar bandeja. \n" +
		"========================== \n");
	//Console::WriteLine("A - Abrir bandeja.");
	//Console::WriteLine("C - Cerrar bandeja.");
	//Console::Write("==========================");

	ConsoleKey key;
	//Console::CursorVisible = false;
	do
	{
		key = Console::ReadKey(true).Key;

		String^ mensaje = "";

		//Asignamos la tecla presionada por el usuario
		switch (key)
		{
		case ConsoleKey::A:
			mensaje = "Abriendo..."; 
			Console::SetCursorPosition(0, 6);
			DoEvents();
			mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
			mensaje = "Abierto.";
			break;

		case ConsoleKey::C:
			mensaje = "Cerrando...";
			Console::SetCursorPosition(0, 6);
			DoEvents2();
			mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);
			mensaje = "Cerrado.";
			break;
		}

		Console::SetCursorPosition(0, 6);
		Console::Write("           ");
		Console::SetCursorPosition(0, 6);
		Console::Write(mensaje);

	} while (key != ConsoleKey::Escape);
    return 0;
}
Esto de Java ya es complicado. ¿Verdad?

Saludos.
__________________
http://electronica-pic.blogspot.com....n-arduino.html Manuales de electrónica general, PIC y Arduino.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Abrir un archivo HTML desde Java Cheswar JAVA 1 09-04-2010 00:01:11
formulario abrir, cerrar arespremium OOP 3 14-08-2007 10:06:21
cerrar sesion windows desde java nazg JAVA 2 09-06-2006 22:29:59
Abrir y cerrar MDI MaJeSTiC Varios 2 03-08-2004 22:00:29
Cerrar bandeja CDs JMGR Varios 6 27-07-2003 15:52:12


La franja horaria es GMT +2. Ahora son las 16:20:20.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi