gpt4 book ai didi

java - 如何将批处理脚本多选集成到JAVA GUI中?

转载 作者:可可西里 更新时间:2023-11-01 10:46:05 24 4
gpt4 key购买 nike

2014 年 7 月 27 日编辑

请仔细阅读,因为我的问题有点复杂

你好,我想编写一个涉及 JAVA GUI、批处理文件和命令提示符的编码。

我的部分答案来自这个网站:Batch scripting multiple selection

这是我现在在我的批处理文件中的内容 [例如]:

echo.
echo Selection time!
echo.
echo 1. My father is Joe
echo 2. My mother is Audrey
echo 3. My brother is Jerry
echo 4. My elder sister is June
echo 5. My youngest sister is Awy
echo 6. Include All
echo.

:getOptions
set /p "choices=Type the number without spacing (e.g. 1,2,3): "

if not defined choices (
echo Please enter a valid option
goto getOptions
)

for %%a in (%choices%) do if %%a EQU 6 set choices=1,2,3,4,5
for %%i in (%choices%) do call :option-%%i

echo.
echo Done
pause
exit

:option-1
echo My father is Joe > Family.txt
exit /B

:option-2
echo My mother is Audrey > Family.txt
exit /B

:option-3
echo My brother is Jerry > Family.txt
exit /B

:option-4
echo My elder sister is June > Family.txt
exit /B

:option-5
echo My youngest sister is Awy > Family.txt
exit /B

接下来,我还想将这个批处理文件包含到一个 Java GUI 中,其中将有几个复选框供用户选择,当用户勾选 box #1 时,< strong>box #2 和 box #3 或者它可能会按顺序勾选复选框,但随后当用户单击“确定”时。它会将勾选框的值传递给批处理文件(它将变为 1,2,3 或 1,3,2 或 2,3,1),然后它会在命令提示符下运行。

这是我的 java 文件中现在的内容 [例如]:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JCheckBox;
import java.awt.Window.Type;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class GUI extends JFrame {

private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI frame = new GUI();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
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) {
}
});
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) {
}
});
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) {
}
});
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) {
}
});
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) {
}
});
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) {
}
});
chckbxAll.setBounds(45, 149, 97, 23);
contentPane.add(chckbxAll);
}
}

我刚刚学习了 java 编码,但是 java GUI 编码对我来说有点困难。我已经开始在批处理文件中编写的代码不仅仅是上面的代码。这就是我来这里寻求帮助的原因。我希望我的解释足够清楚。如果您对我的问题不清楚,请随时问我任何问题。任何帮助将不胜感激!

所以...我的问题是如何将批处理脚本集成到 JAVA GUI 中??

最佳答案

您可以编写 Java 程序并使用 Scanner 从用户那里获取输入:

Scanner in = new Scanner(System.in);

您可以使用以下命令从批处理文件中调用此程序:

@ECHO OFF

%JAVA_HOME%\bin\java MyClass

已为您提供指导,请您自行解决。

干杯!!

关于java - 如何将批处理脚本多选集成到JAVA GUI中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24948004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com