问题描述
我也问了这个问题:如何要将批处理脚本的多个选择集成到JAVA GUI中?
由于我没有得到合适的答案,因此我决定以更简短,更甜蜜的方式在stackoverflow中再次询问.免责声明:我在该网站上编辑了问题.这就是为什么我找不到适合我问题的答案.
As I did not get a suitable answer for my question, that's why I decided to ask again in stackoverflow with a more short and sweet manner. Disclaimer: I edited the question in that site. That's why I couldn't find a suitable answer for my question.
我有此批处理脚本,需要将其集成到Java编码中.但这是我第一次进行集成,因此我不熟悉应如何进行集成.
I have this batch script which needs to be integrated into a java coding. But this is the first time I am doing integration so I am not familiar how it should be done.
如果任何人都可以在该站点回答我的问题,那就太好了.但是,如果不是这样,最好给我一个将多选批处理脚本集成到Java中的示例.
It would be good if anyone can answer my question in that site. But if you aren't, it would also be good to provide me with an example of integrating multiple selection batch script into java.
推荐答案
通过您的原始帖子,我可以得出结论,您的解决方案将非常简单:
eading through your original post, i can conclude that your solution will be quite easy :
private static String cmdLine = "";
private static final String scriptFile = "MYSCRIPT.sh"
public GUI() {
setTitle("FAMILY");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JCheckBox chckbxMyFatherIs = new JCheckBox("My Father is Joe");
chckbxMyFatherIs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(!cmdLine.contains("JOE"))
cmdLine += " JOE ";
}
});
chckbxMyFatherIs.setBounds(45, 48, 137, 23);
contentPane.add(chckbxMyFatherIs);
JCheckBox chckbxNewCheckBox = new JCheckBox("My Mother is Audrey");
chckbxNewCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!cmdLine.contains("AUDREY"))
cmdLine += " AUDREY ";
}
});
chckbxNewCheckBox.setBounds(196, 48, 198, 23);
contentPane.add(chckbxNewCheckBox);
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("My Bother is Jerry");
chckbxNewCheckBox_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!cmdLine.contains("JERRY"))
cmdLine += " JERRY ";
}
});
chckbxNewCheckBox_1.setBounds(45, 97, 137, 23);
contentPane.add(chckbxNewCheckBox_1);
JCheckBox chckbxNewCheckBox_2 = new JCheckBox("My eldest Sister is June ");
chckbxNewCheckBox_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!cmdLine.contains("JUNE"))
cmdLine += " JUNE ";
}
});
chckbxNewCheckBox_2.setBounds(196, 97, 198, 23);
contentPane.add(chckbxNewCheckBox_2);
JCheckBox chckbxNewCheckBox_3 = new JCheckBox("My youngest sister is Awy");
chckbxNewCheckBox_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!cmdLine.contains("AWY"))
cmdLine += " AWY ";
}
});
chckbxNewCheckBox_3.setBounds(196, 149, 198, 23);
contentPane.add(chckbxNewCheckBox_3);
JCheckBox chckbxAll = new JCheckBox("All");
chckbxAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cmdLine = "JOE AUDREY JERRY JUNE AWY";
}
});
chckbxAll.setBounds(45, 149, 97, 23);
contentPane.add(chckbxAll);
}
您还需要为确定"按钮设置一个事件监听器,您可以在其中调用:
You will also need an event-listener for your OK-button, in which you can call:
Runtime.getRuntime().exec(scriptFile + cmdLine);
提醒您:这只会将参数添加到您的列表中,删除(通过取消选中框)也需要处理……我想您现在知道如何.考虑使用列表而不是一个字符串...从而减少了混乱,并允许动态查找/删除/添加参数.
Mind you : this will only ADD parameters to your list, removal (via un-ticking the boxes) also needs to be handled ... i think you now know how.Consider using a list instead of one single string ... thats less messy and allows for dynamic lookup/removal/addition of parameters.
这篇关于是否将批处理脚本集成到Java GUI中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!