将选项窗格放在字符串变量中

时间:2014-02-19 15:14:58

标签: java swing joptionpane

好的,我不确定这是否是提出问题的正确网页。我是学习Java的新手,不懂任何编程语言。我正在自学,以编写一个特定的程序。所以,如果这不是BASIC问题的地方,那么如果有人有另一页让我尝试,我想知道。

我想学习如何做到这一点。

所以我的问题是:

我已经写了一个字符串变量,现在我想放入一个选项窗格,它会弹出一个对话框,人们会输入一个答案,答案会出现在字符串变量的段落中。我将选项窗格放在字符串变量的前面,并在字符串变量段落中打印出来。但我想我需要把它们联系在一起的东西?

我有意义吗?

这是我的刺痛代码

package intro.pkg2;

public class Intro2 {
    public static void main(String[] args) {
        String Intro = " Introduction \n Nishkian Monks, PLLC the established this \n manual in an effort to ensure the fair and consistent application \n  of Company policies and procedures among all employees.  The manual \n is intended to promote understanding within the organizationand to \n outline the privileges of employment.  It supersedes any previous employee \n handbook, manual or administrative memorandum that you may have received. \n This Personnel Policy Manual does not constitute an employment agreement, but \n has been established to identify the obligations that the Company assumes toward \n its staff and vice versa.  The policies contained herein are intended to stress \n the values of fair play, courtesy, and teamwork. This manual is to be used as a \n working guide for all personnel in the day-to-day work routine.  It is anticipated \n the manual will be amended periodically to include new policies and procedures and/or \n to make policy changes. From time to time, you may have questions about your job \n and/or company policy.  You are encouraged to discuss with the Principals, questions \n or problems related to any matters which may be affecting your performance.  You are \n also encouraged to offer suggestions for the improvement of services, simplification of \n operations, saving of material of time, prevention of accidents, reductions of cost, or \n anything else you think will make the Company a better place to work.";

        System.out.println(Intro);
    }    
}

这是问题框的代码

package company;
import javax.swing.JOptionPane;

public class Company {

    public static void main(String[] args) {
        String company_name;
        company_name = JOptionPane.showInputDialog("Company Name");
        JOptionPane.showMessageDialog(null, company_name);
    }
}

你们都很惊讶,我想通过你发给我的链接我会弄明白的。我知道我刚刚开始,真的你愿意帮助他们!我相信我会回来提出更多问题,谢谢你们!

2 个答案:

答案 0 :(得分:2)

显示一个对话框,要求用户输入字符串:

String inputValue = JOptionPane.showInputDialog("Please input a value");

详细了解如何使用JOptionPane here

答案 1 :(得分:0)

将用户输入附加到初始字符串值的最简单的贪婪方法是执行以下操作:

String initialString = "your initial text";
String usersReply = JOptionPane.showInputDialog("Dialog Message"); //user's reply
String finalString = initialString + usersReply; //combine the Strings

但是,您可以使用默认文本要求JOptionPane:

String input = (String) JOptionPane.showInputDialog(null, 
            "Dialog Message", "Dialog Title",
            JOptionPane.QUESTION_MESSAGE, null,null, "your initial text");