ckground(background);
g2.clearRect(0, 0, d.width, d.height);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(jfcBlue);
double tseconds = duration-seconds;
if (tseconds > 0.0)
{
int num = 20;
int progress = (int) (tseconds / duration * num);
double hh = ((double) (d.height - 4) / (double) num);
double ww = (int)(d.width-4);
double x = 0.0;
for ( ; x < progress; x+=1.0)
{
g2.fill(new Rectangle2D.Double(d.width-ww-2, x*hh+2, ww, hh));
g2.fill3DRect((int)(d.width-ww-2),(int) (x*hh+2),(int) ww, (int)hh,true);
}
g2.setColor(jfcDarkBlue);
for ( ; x < num; x+=1.0)
{
g2.fill(new Rectangle2D.Double(d.width-ww-2, x*hh+2, ww, hh));
g2.fill3DRect((int)(d.width-ww-2),(int) (x*hh+2),(int) ww, (int)hh,true);
}
}
}
public void start()
{
pbThread = new Thread(this);
pbThread.setName("PlaybackMonitor");
pbThread.start();
}
public void stop()
{
if (pbThread != null)
{
pbThread.interrupt();
}
pbThread = null;
}
public void run()
{
while (pbThread != null)
{
try
{
pbThread.sleep(99);
}
catch (Exception e)
{
break;
}
repaint();
}
pbThread = null;
}
public void addVolume()
{
changeVolume(false);
initVolume();
}
public void minusVolume()
{
changeVolume(true);
initVolume();
}
//control sound volume.
private void changeVolume(boolean bIsMinus)
{
try
{
Runtime rt = Runtime.getRuntime();
//Sound Control mngPathTool
tool = new mngPathTool();
String sexec;
if(bIsMinus)
sexec= tool.getCurPath()+ "\\binex\\VolumeControl.exe 2";
else
sexec= tool.getCurPath()+ "\\binex\\VolumeControl.exe 1";
rt.exec(sexec);
}catch(Exception e1){e1.printStackTrace(); }
}
}
// End VolumeTracker
创建一个JFrame用于显示 VolumeControl.java
设置页面背景,创建显示上述Panel的容器.
创建对话框用于弹出显示音量控制界面 JVolumeDlg.java
创建一个对话框来显示上个步骤生成的Frame,并提供事件控制容器.
事件流向---> JVolumeDlg -- VolumeControl --- VolumeTracker
总结
Java Runtime 接口提供了调用其他应用程序的接口,通过这个接口,可以实现对
计算机硬件的控制和监控. 同时通过界面线程可以实现相对复杂的应用
程序界面的开发。