- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如:
Runtime rt = Runtime.getRuntime();
创建Runtime rt
Process p1 = rt.exec("C:/Windows/System32/calc.exe");
创建Process p1
上Runtime rt
.
然后p1.destroy();
将摧毁Process p1
.
我的问题是:如果我有多个Process
(例如 p1
、 p2
和 p3
),我该如何 destroy()
一次性全部消灭掉,而不是一一消灭?
对于列表,我如何在我的代码中实现列表?我还没有使用过列表和数组,尽管我尝试过学习如何使用它们,但我想这是通过示例进行教学更容易的事情之一......
另外,一个 for-loop
至destroy()
已经向我提到了这些流程,但是我该如何使用 Process
来解决这个问题? ?
这是我的代码:
package tf2_account_chief;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.util.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class TF2_Account_Chief extends JPanel implements ActionListener {
private static JFrame f = new JFrame("TF2 Account C.H.I.E.F.");
private JLabel runL = new JLabel("Check box to run!");
private JLabel runnableTogetherLabel = new JLabel("How many idlers would you like to run at a time?");
private JCheckBox boxRun = new JCheckBox();
private static JTextField runnableTogetherInput = new JTextField();
private JButton runButton = new JButton("Run!");
private static Image BGimg;
private static int allSets, setsRun, runnableTogether, totalRunnable, run;
private static int processesArray;
private static final String dir = System.getProperty("user.dir");
public void launchFrame() {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack(); //Adjusts panel to components for display
f.setVisible(true);
f.add(runL);
f.add(boxRun);
f.add(runnableTogetherInput);
f.add(runnableTogetherLabel);
f.add(runButton);
f.setSize(500, 500);
runL.setSize(500, 50);
boxRun.setSize(20, 15);
runnableTogetherInput.setSize(25, 15);
runnableTogetherLabel.setSize(275, 25);
runButton.setSize(60, 25);
f.setLocation(0, 0);
runL.setLocation(50, 50);
boxRun.setLocation(95, 100);
runnableTogetherInput.setLocation(285, 5);
runnableTogetherLabel.setLocation(0, 0);
runButton.setLocation(325, 0);
boxRun.addActionListener(this);
runButton.addActionListener(this);
}
private void Processes() throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();
// "runnableTogether" will be the number that the user inputs in the GUI
switch (runnableTogether) {
case 128:
Process p128 = rt.exec(dir + "/run/Idle128.bat");
case 127:
Process p127 = rt.exec(dir + "/run/Idle127.bat");
case 126:
Process p126 = rt.exec(dir + "/run/Idle126.bat");
case 125:
Process p125 = rt.exec(dir + "/run/Idle125.bat");
case 124:
Process p124 = rt.exec(dir + "/run/Idle124.bat");
case 123:
Process p123 = rt.exec(dir + "/run/Idle123.bat");
case 122:
Process p122 = rt.exec(dir + "/run/Idle122.bat");
case 121:
Process p121 = rt.exec(dir + "/run/Idle121.bat");
case 120:
Process p120 = rt.exec(dir + "/run/Idle120.bat");
case 119:
Process p119 = rt.exec(dir + "/run/Idle119.bat");
case 118:
Process p118 = rt.exec(dir + "/run/Idle118.bat");
case 117:
Process p117 = rt.exec(dir + "/run/Idle117.bat");
case 116:
Process p116 = rt.exec(dir + "/run/Idle116.bat");
case 115:
Process p115 = rt.exec(dir + "/run/Idle115.bat");
case 114:
Process p114 = rt.exec(dir + "/run/Idle114.bat");
case 113:
Process p113 = rt.exec(dir + "/run/Idle113.bat");
case 112:
Process p112 = rt.exec(dir + "/run/Idle112.bat");
case 111:
Process p111 = rt.exec(dir + "/run/Idle111.bat");
case 110:
Process p110 = rt.exec(dir + "/run/Idle110.bat");
case 109:
Process p109 = rt.exec(dir + "/run/Idle109.bat");
case 108:
Process p108 = rt.exec(dir + "/run/Idle108.bat");
case 107:
Process p107 = rt.exec(dir + "/run/Idle107.bat");
case 106:
Process p106 = rt.exec(dir + "/run/Idle106.bat");
case 105:
Process p105 = rt.exec(dir + "/run/Idle105.bat");
case 104:
Process p104 = rt.exec(dir + "/run/Idle104.bat");
case 103:
Process p103 = rt.exec(dir + "/run/Idle103.bat");
case 102:
Process p102 = rt.exec(dir + "/run/Idle102.bat");
case 101:
Process p101 = rt.exec(dir + "/run/Idle101.bat");
case 100:
Process p100 = rt.exec(dir + "/run/Idle100.bat");
case 99:
Process p99 = rt.exec(dir + "/run/Idle99.bat");
case 98:
Process p98 = rt.exec(dir + "/run/Idle98.bat");
case 97:
Process p97 = rt.exec(dir + "/run/Idle97.bat");
case 96:
Process p96 = rt.exec(dir + "/run/Idle96.bat");
case 95:
Process p95 = rt.exec(dir + "/run/Idle95.bat");
case 94:
Process p94 = rt.exec(dir + "/run/Idle94.bat");
case 93:
Process p93 = rt.exec(dir + "/run/Idle93.bat");
case 92:
Process p92 = rt.exec(dir + "/run/Idle92.bat");
case 91:
Process p91 = rt.exec(dir + "/run/Idle91.bat");
case 90:
Process p90 = rt.exec(dir + "/run/Idle90.bat");
case 89:
Process p89 = rt.exec(dir + "/run/Idle89.bat");
case 88:
Process p88 = rt.exec(dir + "/run/Idle88.bat");
case 87:
Process p87 = rt.exec(dir + "/run/Idle87.bat");
case 86:
Process p86 = rt.exec(dir + "/run/Idle86.bat");
case 85:
Process p85 = rt.exec(dir + "/run/Idle85.bat");
case 84:
Process p84 = rt.exec(dir + "/run/Idle84.bat");
case 83:
Process p83 = rt.exec(dir + "/run/Idle83.bat");
case 82:
Process p82 = rt.exec(dir + "/run/Idle82.bat");
case 81:
Process p81 = rt.exec(dir + "/run/Idle81.bat");
case 80:
Process p80 = rt.exec(dir + "/run/Idle80.bat");
case 79:
Process p79 = rt.exec(dir + "/run/Idle79.bat");
case 78:
Process p78 = rt.exec(dir + "/run/Idle78.bat");
case 77:
Process p77 = rt.exec(dir + "/run/Idle77.bat");
case 76:
Process p76 = rt.exec(dir + "/run/Idle76.bat");
case 75:
Process p75 = rt.exec(dir + "/run/Idle75.bat");
case 74:
Process p74 = rt.exec(dir + "/run/Idle74.bat");
case 73:
Process p73 = rt.exec(dir + "/run/Idle73.bat");
case 72:
Process p72 = rt.exec(dir + "/run/Idle72.bat");
case 71:
Process p71 = rt.exec(dir + "/run/Idle71.bat");
case 70:
Process p70 = rt.exec(dir + "/run/Idle70.bat");
case 69:
Process p69 = rt.exec(dir + "/run/Idle69.bat");
case 68:
Process p68 = rt.exec(dir + "/run/Idle68.bat");
case 67:
Process p67 = rt.exec(dir + "/run/Idle67.bat");
case 66:
Process p66 = rt.exec(dir + "/run/Idle66.bat");
case 65:
Process p65 = rt.exec(dir + "/run/Idle65.bat");
case 64:
Process p64 = rt.exec(dir + "/run/Idle64.bat");
case 63:
Process p63 = rt.exec(dir + "/run/Idle63.bat");
case 62:
Process p62 = rt.exec(dir + "/run/Idle62.bat");
case 61:
Process p61 = rt.exec(dir + "/run/Idle61.bat");
case 60:
Process p60 = rt.exec(dir + "/run/Idle60.bat");
case 59:
Process p59 = rt.exec(dir + "/run/Idle59.bat");
case 58:
Process p58 = rt.exec(dir + "/run/Idle58.bat");
case 57:
Process p57 = rt.exec(dir + "/run/Idle57.bat");
case 56:
Process p56 = rt.exec(dir + "/run/Idle56.bat");
case 55:
Process p55 = rt.exec(dir + "/run/Idle55.bat");
case 54:
Process p54 = rt.exec(dir + "/run/Idle54.bat");
case 53:
Process p53 = rt.exec(dir + "/run/Idle53.bat");
case 52:
Process p52 = rt.exec(dir + "/run/Idle52.bat");
case 51:
Process p51 = rt.exec(dir + "/run/Idle51.bat");
case 50:
Process p50 = rt.exec(dir + "/run/Idle50.bat");
case 49:
Process p49 = rt.exec(dir + "/run/Idle49.bat");
case 48:
Process p48 = rt.exec(dir + "/run/Idle48.bat");
case 47:
Process p47 = rt.exec(dir + "/run/Idle47.bat");
case 46:
Process p46 = rt.exec(dir + "/run/Idle46.bat");
case 45:
Process p45 = rt.exec(dir + "/run/Idle45.bat");
case 44:
Process p44 = rt.exec(dir + "/run/Idle44.bat");
case 43:
Process p43 = rt.exec(dir + "/run/Idle43.bat");
case 42:
Process p42 = rt.exec(dir + "/run/Idle42.bat");
case 41:
Process p41 = rt.exec(dir + "/run/Idle41.bat");
case 40:
Process p40 = rt.exec(dir + "/run/Idle40.bat");
case 39:
Process p39 = rt.exec(dir + "/run/Idle39.bat");
case 38:
Process p38 = rt.exec(dir + "/run/Idle38.bat");
case 37:
Process p37 = rt.exec(dir + "/run/Idle37.bat");
case 36:
Process p36 = rt.exec(dir + "/run/Idle36.bat");
case 35:
Process p35 = rt.exec(dir + "/run/Idle35.bat");
case 34:
Process p34 = rt.exec(dir + "/run/Idle34.bat");
case 33:
Process p33 = rt.exec(dir + "/run/Idle33.bat");
case 32:
Process p32 = rt.exec(dir + "/run/Idle32.bat");
case 31:
Process p31 = rt.exec(dir + "/run/Idle31.bat");
case 30:
Process p30 = rt.exec(dir + "/run/Idle30.bat");
case 29:
Process p29 = rt.exec(dir + "/run/Idle29.bat");
case 28:
Process p28 = rt.exec(dir + "/run/Idle28.bat");
case 27:
Process p27 = rt.exec(dir + "/run/Idle27.bat");
case 26:
Process p26 = rt.exec(dir + "/run/Idle26.bat");
case 25:
Process p25 = rt.exec(dir + "/run/Idle25.bat");
case 24:
Process p24 = rt.exec(dir + "/run/Idle24.bat");
case 23:
Process p23 = rt.exec(dir + "/run/Idle23.bat");
case 22:
Process p22 = rt.exec(dir + "/run/Idle22.bat");
case 21:
Process p21 = rt.exec(dir + "/run/Idle21.bat");
case 20:
Process p20 = rt.exec(dir + "/run/Idle20.bat");
case 19:
Process p19 = rt.exec(dir + "/run/Idle19.bat");
case 18:
Process p18 = rt.exec(dir + "/run/Idle18.bat");
case 17:
Process p17 = rt.exec(dir + "/run/Idle17.bat");
case 16:
Process p16 = rt.exec(dir + "/run/Idle16.bat");
case 15:
Process p15 = rt.exec(dir + "/run/Idle15.bat");
case 14:
Process p14 = rt.exec(dir + "/run/Idle14.bat");
case 13:
Process p13 = rt.exec(dir + "/run/Idle13.bat");
case 12:
Process p12 = rt.exec(dir + "/run/Idle12.bat");
case 11:
Process p11 = rt.exec(dir + "/run/Idle11.bat");
case 10:
Process p10 = rt.exec(dir + "/run/Idle10.bat");
case 9:
Process p9 = rt.exec(dir + "/run/Idle9.bat");
case 8:
Process p8 = rt.exec(dir + "/run/Idle8.bat");
case 7:
Process p7 = rt.exec(dir + "/run/Idle7.bat");
case 6:
Process p6 = rt.exec(dir + "/run/Idle6.bat");
case 5:
Process p5 = rt.exec(dir + "/run/Idle5.bat");
case 4:
Process p4 = rt.exec(dir + "/run/Idle4.bat");
case 3:
Process p3 = rt.exec(dir + "/run/Idle3.bat");
case 2:
Process p2 = rt.exec(dir + "/run/Idle2.bat");
case 1:
Process p1 = rt.exec(dir + "/run/Idle1.bat");
Thread.sleep(5000);
//destroy all Processes here or at destroyProcesses()
break;
default:
System.exit(0);
}
}
private void processesAray() {
}
private void destroyProcesses() {
}
public void actionPerformed(final ActionEvent e) {
if (boxRun.isSelected()) {
System.out.println("running!");
try {
if (runnableTogether > 0 && runnableTogether < 128) {
firstEvent1();
}
else {
System.exit(0);
}
}
catch(Exception ex) {
}
}
else {
System.out.println("not running!");
}
if(e.getSource() == runButton){
//runnableTogetherString = (runnableTogetherInput.getText());
runnableTogether = Integer.parseInt(runnableTogetherInput.getText());
try {
if (runnableTogether > 0 && runnableTogether < 128) {
firstEvent1();
}
else {
System.exit(0);
}
}
catch(Exception ex) {
}
}
}
private void firstEvent1() throws IOException {
totalRunnable = runnableTogether*17;
try {
if (allSets <= totalRunnable) {
if (setsRun <= runnableTogether) {
Processes();
setsRun++;
/*do {
}while(setsRun <= runnableTogether);*/
Thread.sleep(5000);
//p1.destroy(); // Does not work right now
/*p2.destroy();
p3.destroy();
p4.destroy();
p5.destroy();
p6.destroy();
p7.destroy();
p8.destroy();*/
}
allSets = allSets + runnableTogether;
}
} catch (Exception ex) {
}
}
public static void main(String[] args) throws IOException {
TF2_Account_Chief gui = new TF2_Account_Chief();
gui.launchFrame();
Container contentPane = f.getContentPane();
contentPane.add(new TF2_Account_Chief());
//BGimg = ImageIO.read(new File(dir + "/tf2.jpg"));
}
public void paintComponent(Graphics g) {
//g.drawImage(BGimg, 0, 0, null);
}
}
有人知道怎么做吗?
最佳答案
您可以创建一个ArrayList或进程
// Create runtime and array
Runtime rt = Runtime.getRuntime();
List<Process> processes = new ArrayList<Process>();
swtich(bleh){
....
// Add every process
case 1:
processes.add(rt.exec("my command 1"));
case 2:
processes.add(rt.exec("my command 2"));
....
case n:
processes.add(rt.exec("my command n"));
}
// Destroy all items in the list, iterating the array
destroyProcesses(processes)
基本实现可能在哪里
private void destroyProcesses(List<Process> processes){
if (processes == null)
return;
else{
for (Process thisProcess : processes)
thisProcess.destroy();
processes.clear();
}
}
关于java - 如何根据用户输入运行某些进程,然后相应地销毁它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17462023/
我有一个测试即将进行,我想澄清两个有关参数的问题。 在我的笔记中指出,将参数传递给函数的推荐方法是使用“按引用传递” const type& x; // for "in" parameters
当我通过 OMG 2.5(Beta)推广的 UML 规范阅读以下概念时: in: Indicates that Parameter values are passed in by the caller
我试图在用户按下 Enter 时触发一个函数。我将此输入设置为只读的原因是限制用户在填充值后修改输入中的值。 该值来自将在点击属性中触发的弹出窗口。问题是 keyup.enter 没有触发该输入。 代
我在jQuery中使用模式弹出窗口控件,该弹出窗口具有由jQuery Tokenize输入插件提供动力的输入文本。问题是,当我在模式弹出文本框中键入内容时, token 化插件的搜索结果显示为隐藏在弹
我有一个问题。当我选中复选框时,系统工作正常,总值发生变化,但一旦我修改文本输入,它就会变为 0。我需要将此文本框输入排除在更改值之外。 这是 html: $15000 $
我正在努力让它发挥作用,但还是有些不对劲。 我想用 CSS 设置提交按钮的样式以匹配我已有的按钮。 风格: input[type="button"], input[type="submit"], b
import java.util.*;; public class selection { Scanner in=new Scanner(System.in); private
这可能是一个非常菜鸟的问题。假设我有一个带宽限制为 100MB/s 的网卡,那么输入/输出带宽是否有可能达到该限制 同时 ?或者我会在任何时候遇到这个不等式:in bandwidth + out ba
看着这个问题,Fill immutable map with for loop upon creation ,我很好奇是什么this表示在 Map(1 -> this) . scala> Map(1
我有这样的东西 一个 乙 问? 是或否 数字 数字或零 我想做的是: 如果 B1 = “Y”,则让用户在 B2 中输入一个数字。 如果 B1 = “N”,则将 B2 中的值更改为零,并且不允许用户在
我有一个包含许多列的表,我想添加 input标题单元格内的字段,但我希望输入适合根据正文内容的宽度。 这是没有 input 的样子领域: 这就是 input 的样子领域: 可以看出,像“index”和
关于为 FTP 客户端设置传出和传入文件夹,您遵循哪些最佳实践(如果有)?我们通常使用“outgoing”和“incoming”,但无论你如何表述方向,它都可以有两种解释方式,具体取决于名称相对于哪一
我正在尝试“求解”给定 d 的 Pell 方程:x^2 - d * y^2 = 1,或者至少我想得到最小的 x > 0 来求解方程。到目前为止,一切都很好。这是我的 Haskell 代码 minX :
我是VS Code的新手,可以使用Ctrl + Enter将代码运行到python交互式窗口中。我希望光标自动移动到下一行,因此我可以逐行浏览代码。 能做到吗? 最佳答案 如this blog pos
我正在创建一个 bool 值矩阵/二维数组,并且我想为 dategrid 推断一种不仅仅是“ANY”的类型。 let yearRange = [2000,2001,2002,2003,2004]; l
我有两个排序的列表,例如 a = [1, 4, 7, 8] b = [1, 2, 3, 4, 5, 6] 我想知道a中的每个项目是否在b中。对于上面的示例,我想找到 a_in_b = [True, T
菜鸟警报 这很奇怪 - 当我编写以下代码时,尝试在 AngularJS 中创建自定义指令: myModule.directive('myTab', function(){ console.lo
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
假设我正在使用 gdscript 静态类型,并且对于一个函数参数,我事先不知道我会得到什么。这就是 python 中 typing.Any 的作用。如何使用 gdscript 做到这一点? 似乎 Va
我使用 dropzone 上传多个图像,并且工作正常,直到我想为每个图像插入品牌和网址。 我遇到的唯一问题是,当我要从输入字段获取值时,我会从服务器获取来自字段(品牌、网址)的未定义值,但如果我使用静
我是一名优秀的程序员,十分优秀!