簡體   English   中英

如果選擇了“全部”選項,如何確保其他選項不運行?

[英]if an option “ALL” is selected, how do I make sure other options does not run?

所以這是我的問題...我正在使用java eclipse。 我設計了這幾個選項,以允許用戶在Java GUI的復選框中打勾。 但是我有一個選項為“全部”,如何確保在選中“所有”選項時,除此“所有”選項之外,其他選項都不會運行?

我該怎么做才能解決這個問題?

這是我的Java編碼。

btnStart.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent args)
        {
            //if checkbox_4 (ALL) is being selected, the other checkboxes will be disabled/not running so there will not be overlapping..
            if(checkbox_4.isSelected())
            {
                try
                {   
                    String command = "cmd /c start /wait "+DetectDrive+"\\All.bat";
                    Process p = Runtime.getRuntime().exec(command);
                    p.waitFor();
                } 
                catch (IOException | InterruptedException e1)
                {
                    e1.printStackTrace();
                }
            }

            if(checkbox.isSelected())
            {
                try
                {   
                    String command = "cmd /c start /wait "+DetectDrive+"\\1.bat";
                    Process p = Runtime.getRuntime().exec(command);
                    p.waitFor();
                } 
                catch (IOException | InterruptedException e1)
                {
                    e1.printStackTrace();
                }

            //so on and so forth..
            }
        }
    }

您應該在所有其他復選框上使用setEnabled(false)

取消選中“所有”復選框后,請務必重新啟用它們。

只需使用IF ELSE語句即可。

如果選擇了checkbox_4,則運行它。 否則,請檢查是否勾選了其他框。 運行。 簡短。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM