Windows XP/7에서 랩톱 화면 밝기를 변경하는 Java 응용 프로그램을 만들고 싶습니다. 제발 도와주세요Java 응용 프로그램에서 노트북 화면 밝기를 변경하는 방법은 무엇입니까?
2
A
답변
0
자바에서 표준 API가 있다고 생각하지 않습니다.
하지만 Windows에서 .NET으로 할 수있는 것 같습니다. 참조 : What API call would I use to change brightness of laptop (.NET)?
언제나 JNI 인터페이스를 사용하여 C++로 작성된 원시 메소드를 호출 할 수 있습니다. 이는 일시적인 해결책 일 수 있습니다.
2
다른 사람들이 언급했듯이 사용할 공식 API는 없습니다. 그러나, Windows Powershell을 사용하면 (아무 것도 다운로드 할 필요가 없음), WmiSetBrightness을 사용하여 비자가있는 모든 Windows PC 또는 나중에 설치해야하는 간단한 해결 방법을 만들 수 있습니다. 다음 {밝기} 당신이에서 화면 표시를 설정하려는 밝기가 어디
BrightnessManager.setBrightness({brightness});
전화
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BrightnessManager {
public static void setBrightness(int brightness)
throws IOException {
//Creates a powerShell command that will set the brightness to the requested value (0-100), after the requested delay (in milliseconds) has passed.
String s = String.format("$brightness = %d;", brightness)
+ "$delay = 0;"
+ "$myMonitor = Get-WmiObject -Namespace root\\wmi -Class WmiMonitorBrightnessMethods;"
+ "$myMonitor.wmisetbrightness($delay, $brightness)";
String command = "powershell.exe " + s;
// Executing the command
Process powerShellProcess = Runtime.getRuntime().exec(command);
powerShellProcess.getOutputStream().close();
//Report any error messages
String line;
BufferedReader stderr = new BufferedReader(new InputStreamReader(
powerShellProcess.getErrorStream()));
line = stderr.readLine();
if (line != null)
{
System.err.println("Standard Error:");
do
{
System.err.println(line);
} while ((line = stderr.readLine()) != null);
}
stderr.close();
}
}
그리고 :
당신이해야 할 모든 작업 공간에이 클래스를 복사입니다 0은 지원되는 밝기가 가장 낮고 100이 가장 밝습니다.
powershell 코드에 대한 anquegi에게 큰 감사를 표한 결과,이 명령을 실행하기 위해 적응한 here이 발견되었습니다.
불행하게도 그것은 work.It는 표준 오차> 10 'Windows에서이 오류를 제공하지 않습니다 은 Get-WmiObject를이 : 줄에 지원되지 않음 : 1 개 문자 : 42 + ... myMonitor = GET-WmiObject를 -namespace을 , ManagementException + FullyQualifiedErrorId [-WmiObject를 가져 오기] (:) : 루트 \ WMI -Class WmiMonitorBright ... +' – GOXR3PLUS
Resume-> '+ CategoryInfo : InvalidOperation GetWMIManagementException, Microsoft.PowerShell.Commands.GetWmiObjectCommand을 당신은 할 수 없습니다 null 값을 가지는 식의 메서드를 호출합니다. 라인에서 1 문자 : 111 + ... torBrightnessMethods; $ myMonitor.wmisetbrightness ($ 지연 $ 밝기) + ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation (:) []의 RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull' – GOXR3PLUS