2014-02-19 28 views
0

好吧我不确定这是否是正确的网页来问我的问题。我是学习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); 
    } 
} 

你们都是惊人的,我想与你送我我要的链接代码弄明白。我知道我刚刚开始,真的很乐意帮助初学者!我相信我会回来更多的问题,谢谢大家!

+0

你可以发布你有的代码吗? – user2277872

+0

如果你只是一个初学者,我建议你从比使用Swing组件和创建GUI更简单的事情开始。 – ujvl

回答

2

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

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

了解更多如何使用JOptionPane的here

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");