如何批处理脚本多重选择融入JAVA GUI? [英] How to integrate batch script multiple selections into JAVA GUI?

查看:343
本文介绍了如何批处理脚本多重选择融入JAVA GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDITED 27/7/2014

EDITED 27/7/2014

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

您好,我想做一个编码由此涉及到一个JAVA GUI,批处理文件和命令提示符。

Hi, I wanted to do a coding whereby it involves a JAVA GUI, batch file and command prompt.

我从这个网站我的答案的一部分:批处理脚本多重选择

I got part of my answer from this website: Batch scripting multiple selection

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

Here's what I have now in my batch file [FOR EXAMPLE]:

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即会出现少数几个复选框供用户选择,当用户选中的框#1 ,< STRONG>盒#2 和框#3 或也许这将是滴答序列中的复选框但是当用户点击OK。它会通过勾选框值批处理文件(它将成为 1,2,3或1,3,2或2,3,1 ),然后它会在命令提示符下运行。

Next, with that, I would also like to include this batch file into a java GUI whereby there will be a few checkboxes for the user to select and when the user ticked box #1, box #2 and box #3 or maybe it would be ticking the check box in sequence but then when the user clicked "OK". It will pass the ticked boxes value to the batch file (it will become 1,2,3 or 1,3,2 or 2,3,1) and then it will run in the command prompt.

这就是我现在在我的Java文件[例如]:

Here's what I have now in my java file [FOR EXAMPLE]:

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对我来说有点困难。我已经开始编码不仅仅是在批处理文件上面的编码多。这就是为什么我来到这里寻求帮助。我希望我的解释是不够清楚。请随时问我什么,如果你不清楚我的问题。任何帮助将大大AP preciated!

I just learnt coding java but coding java GUI is a bit difficult for me. I have started coding more than just the above coding in the batch file. That's why I came here to seek help. I hope my explanation is clear enough. Please feel free to ask me anything if you are unclear with my question. Any help would be greatly appreciated!

所以...我的问题是如何批量脚本集成到JAVA GUI ??

So... My question is how to integrate batch scripting into JAVA GUI??

推荐答案

更改此行:

if %choices% equ 6 set choices=1,2,3,4,5

本之一:

if "%choices:6=%" neq "%choices%" set choices=1,2,3,4,5

我也建议你使用<一个href=\"http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990\">arrays.

修改例添加

@echo off

:getOptions
set "choices="
set /P "choices=Choices: "
if not defined choices goto :EOF
if "%choices:6=%" neq "%choices%" set choices=1,2,3,4,5,6
echo Execute: %choices%
goto getOptions

输出示例:

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,但你明白了吧

EDIT: I obviously made the error of also include 6 in the replacement, but you get the point!

这篇关于如何批处理脚本多重选择融入JAVA GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆