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

如何将批处理脚本多选集成到JAVA GUI中?,java,windows,batch-file,user-interface,cmd,Java,Windows,Batch File,User Interface,Cmd,2014年7月27日编辑 我的问题有点复杂,请仔细阅读 嗨,我想做一个编码,其中包括一个JavaGUI、批处理文件和命令提示符 我从这个网站上得到了部分答案: 下面是我的批处理文件中的内容[例如]: 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

2014年7月27日编辑

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

嗨,我想做一个编码,其中包括一个JavaGUI、批处理文件和命令提示符

我从这个网站上得到了部分答案:

下面是我的批处理文件中的内容[例如]:

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
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 GUI中,其中将有一些复选框供用户选择,当用户勾选框1、框2和框3时,或者可能会依次勾选复选框,但当用户单击OK时。它将把勾选框值传递给批处理文件,它将变为1,2,3或1,3,2或2,3,1,然后在命令提示符下运行

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

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
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从用户处获取输入:

扫描仪输入=新的ScannerSystem.in

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

@ECHO OFF
%JAVA\u HOME%\bin\JAVA MyClass

已经给了你们一些指示,剩下的就留给你们去弄清楚了

干杯

更改此行:

if %choices% equ 6 set choices=1,2,3,4,5
通过这个:

if "%choices:6=%" neq "%choices%" set choices=1,2,3,4,5
我也建议你使用

编辑:添加了示例

示例输出:

C:\> test.bat
Choices: 1,3,5
Execute: 1,3,5
Choices: 1,2,4,6
Execute: 1,2,3,4,5,6
Choices: 1,6
Execute: 1,2,3,4,5,6
Choices:

编辑:我显然犯了一个错误,在替换中也包括了6个,但你明白了

我不明白这和Java有什么关系?我看到一个批处理文件,但没有Java代码。你的问题是批处理文件??但我想您需要通过批处理文件调用java程序,批处理文件提供了这些选项。。给我一点时间。我需要找到它。这就是为什么我没有包括它。@SachinThapa对不起,我刚刚开始学习java。你介意再解释一下吗?我不太明白。我已经在一个较高的层次上添加了你需要做的事情,将由你来完成。但我是从一个thumbdrive运行这个。这有关系吗?为什么我在使用勾选框时需要扫描仪?当我在CMD中键入时,它无法识别1,6请参见我答案中的编辑。。。请解释清楚你说的“无法识别”是什么意思…阿奇尼,实际上我确实理解你的编码。但是对于您的编码,它无法逐个执行。它就像.%选项%=1,2,3但问题是我不知道如何指出选项1来执行“我的父亲是乔”,然后它将继续执行选项2 etci也尝试使用/f delims=,tokens=1-5%%I in%choices%do set I=%%I set j=%%j set k=%%k set l=%%l set m=%%m,从而将选项与1,2,3 e.g.I分配1分开。但我不知道如何使它改变,从而它将转到选项集。请参阅您在上面发布的同一链接。。。