0
我有一个只有1个按钮的小应用程序。我想要它做的是检查按钮按下时是否正在运行一个进程。它是,做x,如果它不是y。如果进程正在运行,请执行此操作,否则请执行此操作
这是我迄今为止的卑微代码。我知道它只包括按钮,点击和其他任何东西。这个我真的很空白。
public class toggle {
public static void main(String[] args) {
Display myDisplay = new Display();
Shell myShell = new Shell(myDisplay);
myShell.setText("uTorrent Toggle");
myShell.setBounds(120, 120, 220, 120);
myShell.setLayout(new FillLayout());
final Button Start = new Button(myShell, SWT.PUSH);
Start.setText("Start uTorrent");
Start.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Start.setText("Kill uTorrent");
try {
Runtime.getRuntime().exec("/bin/bash -c \"utorrent start\"");
} catch (IOException e) {
e.printStackTrace();
}
}
});
myShell.open();
while (!myShell.isDisposed()) {
if (!myDisplay.readAndDispatch()) myDisplay.sleep();
}
myDisplay.dispose();
}
}