gpt4 book ai didi

java - 如何使用退出代码 : Java 退出程序

转载 作者:行者123 更新时间:2023-11-29 03:10:18 30 4
gpt4 key购买 nike

我有一个 Java 应用程序。我想指定我的控制台应用程序的“退出代码”。如何为 registerButton 应用退出代码?

final JTextField passwordText = new JTextField(20);
passwordText.setBounds(10, 120, 160, 25);
panel.add(passwordText);

JButton loginButton = new JButton("OK");
loginButton.setBounds(10, 150, 80, 25);
panel.add(loginButton);

JButton registerButton = new JButton("CANCEL");
registerButton.setBounds(180, 150, 80, 25);
panel.add(registerButton);

loginButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent actionEvent) {
int i=Integer.parseInt(passwordText.getText());
if(1<=i &&i<4) {
JTextField xField1 = new JTextField(5);
JTextField xField2 = new JTextField(5);
JTextField xField3 = new JTextField(5);
JTextField xField4 = new JTextField(5);

最佳答案

你可以使用 System.exit(0)

public static void exit(int status) Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination. This method calls the exit method in class Runtime. This method never returns normally.

The call System.exit(n) is effectively equivalent to the call:

Runtime.getRuntime().exit(n) Parameters: status - exit status. Throws: SecurityException - if a security manager exists and its checkExit method doesn't allow exit with the specified status. See Also: Runtime.exit(int)

关于java - 如何使用退出代码 : Java 退出程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749438/

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