1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import javafx.application.Application import javafx.scene.Scene import javafx.scene.control.Button import javafx.scene.control.Label import javafx.scene.control.TextField import javafx.scene.layout.VBox import javafx.stage.Stage import java.lang.management.ManagementFactory import java.time.Duration class ProcessViewer : Application() { private val processIdLabel = Label("ID del Proceso:") private val processIdInput = TextField() private val resultLabel = Label("Resultado:") override fun start(primaryStage: Stage) { primaryStage.title = "Visor de Procesos" val layout = VBox(10.0) layout.children.addAll(processIdLabel, processIdInput, resultLabel) val queryButton = Button("Consultar Proceso") queryButton.setOnAction { val processId = processIdInput.text.toLongOrNull() if (processId != null) { val processInfo = getProcessInfo(processId) resultLabel.text = processInfo } else { resultLabel.text = "ID de Proceso no válido." } } layout.children.add(queryButton) val scene = Scene(layout, 300.0, 150.0) primaryStage.scene = scene primaryStage.show() } private fun getProcessInfo(processId: Long): String { val runtimeMXBean = ManagementFactory.getRuntimeMXBean() val processInfo = runtimeMXBean.name if (processInfo.startsWith("$processId@")) { return "Proceso ID: $processId\nInformación: $processInfo" } else { return "No se encontró un proceso con el ID $processId." } } } fun main() { Application.launch(ProcessViewer::class.java) } |