Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:Runtime()在java.lang.Runtime中具有私有aaaccess_Java_Button_Runtime_Exec_Processbuilder - Fatal编程技术网

错误:Runtime()在java.lang.Runtime中具有私有aaaccess

错误:Runtime()在java.lang.Runtime中具有私有aaaccess,java,button,runtime,exec,processbuilder,Java,Button,Runtime,Exec,Processbuilder,我正在尝试执行此操作:当我单击“搜索”按钮时,命令提示窗口打开 我尝试使用ProcessBuilder,没有出现错误,但它不起作用。你能帮我吗 package sys.tool; import java.awt.*; import java.awt.event.*; import javax.swing.*; //Создаем поля public class MainWindow extends JFrame{ private JLabel lcn = new JLabel("E

我正在尝试执行此操作:当我单击“搜索”按钮时,命令提示窗口打开

我尝试使用ProcessBuilder,没有出现错误,但它不起作用。你能帮我吗

package sys.tool;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//Создаем поля
public class MainWindow extends JFrame{
    private JLabel lcn = new JLabel("Enter computer name:");
    private JTextField icn = new JTextField("", 5);
    private JButton search = new JButton("Search");
    private JLabel lun = new JLabel("Enter user name:");
    private  JTextField iun = new JTextField("", 5);
    private JLabel empty = new JLabel("");


    public MainWindow (){
        super("SysAdminTool");
        this.setBounds(100, 100, 700 , 90);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);

        Container container = this.getContentPane();
        container.setLayout(new GridLayout(3, 2 , 1, 1));
        container.add(lcn);
        container.add(icn);

        container.add(lun);
        container.add(iun);

        container.add(empty);
        search.addActionListener(new SearchEventListener());
        container.add(search);
    }

    class  SearchEventListener implements ActionListener{
        public void actionPerformed (ActionEvent e){

           Runtime rt = new Runtime();
           rt.exec(new String[]{"cmd.exe", "/C","start"}); \\Here a make an event for button, to open cmd when I click the button.





        }
    }


    }
从:

每个Java应用程序都有一个类运行时实例,该实例允许应用程序与运行应用程序的环境交互。当前运行时可以从getRuntime方法获得

应用程序无法创建自己的此类实例


因此,我不再使用
newruntime()
尝试
Runtime.getRuntime()

谢谢您的回复,而是开始学习java,我的技能很低。正如我正确理解的那样,如果我想使用runtime,我必须在所有情况下编写
runtime.getRuntime
,不是吗?是的,没错。Java不允许您创建新的运行时对象,因此您必须使用getRuntime()方法来获取Java自动创建的对象。非常感谢您的帮助。