0

Okay I am not sure if this is the right web page to ask my question. I am new to learning Java, do not know any programming languages. I am teaching myself in order to write a specific program. So if this is not the place for BASIC question then if someone has another page for me to try I would like to know.

I want to learn how to do this.

So my question is this:

I have written a string variable, now I want to put in a option pane that brings up a dialog box that people would input a answer and that answer would come up in the paragraph of the string variable. I put the option pane in the front of the string variable and the print out in the string variable paragraph. But I think I need something that ties them together?

Am I making any sense?

This is my code for the sting

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

This is my code for the Question box

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

You all are AMAZING, I think with the links that you sent me I am going to figure it out. I know I am just starting and REALLY you willing to help a starter! I am sure I will be back with more questions, THANK YOU ALL!

2 Answers2

2

Show a dialog asking the user to type in a String:

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

Read more in how to use JOptionPane here

nachokk
  • 14,363
  • 4
  • 24
  • 53
0

The easiest greedy way to attach user's input to an initial String value is to do something like this:

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

However, you may ask for JOptionPane with default text:

String input = (String) JOptionPane.showInputDialog(null, 
            "Dialog Message", "Dialog Title",
            JOptionPane.QUESTION_MESSAGE, null,null, "your initial text");
Kostas Kryptos
  • 4,081
  • 2
  • 23
  • 24