Click to See Complete Forum and Search --> : Dialog Boxes


bostonuser
October 16th, 2007, 11:30 PM
This is a simple program-my question is when you are using control structures such as for loops or switch,
do you write the code using the dialog boxes, for some reason I don't automatically think of the dialog box when writing a program-I don't know why I do this, possibly because I learned assembly language. I found an excellent tutorial on java, but I am curious if you experiment with different pop ups or do you keep it simple when using a control structure like this?

Thanks

import java.io.*;

public class Flooring{
public static void main(String args[]) throws Exception{
int ch;
// local variable declarations
// Outputs for program directions
System.out.println("Welcome to \"My\" Flooring Depot");
System.out.println("\nThis program asks the user to enter a choice of flooring for a new home."
+ "\nPlease enter the number that matches your flooring choice then press" + "\nthe Enter key.");
System.out.println("Enter 1 for Scored Concrete, costs $3000.");
System.out.println("Enter 2 for Carpeting, comes with $5000 allowance.");
System.out.println("Enter 3 for Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
// alternating prompts for input and statements to capture users input
// System.out.print is used instead of System.out.println so the prompt
// stays on the same line as the text
System.out.print("your choice is : ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try{
ch=Integer.parseInt(in.readLine());
switch(ch){
case 1: System.out.println("Scored Carpeting, costs $3000");
break;
case 2: System.out.println("Carpeting, comes with $5000 allowance");
break;
case 3: System.out.println("Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
break;
default: System.out.println("Invalid entry!");
break;
}
}
catch(NumberFormatException ex){
System.out.println(ex.getMessage() + " is not a numeric value.");
System.exit(0);
}
}
}

dlorde
October 17th, 2007, 04:56 AM
...when you are using control structures such as for loops or switch, do you write the code using the dialog boxes?No, why would I? What do control structures have to do with dialog boxes?

Dialog boxes are for user input or notification in GUI applications. Control structures are for directing the flow of execution.

On two occasions, I have been asked [by members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question...
C. Babbage

bostonuser
October 17th, 2007, 07:54 AM
Because my text wants dialog boxes in most cases

dlorde
October 17th, 2007, 09:49 AM
:confused: You asked : "when you are using control structures such as for loops or switch, do you write the code using the dialog boxes?". I replied saying no, why would you want to - control structures and dialog boxes are not functionally related.

If you want to use dialogs, use dialogs. If you don't want to use dialogs, don't, but there is no logical link between control structures and dialogs.

If you'd like to ask a coherent question, I suggest you go ahead and ask it, because so far it has all been gibberish.

Do you want to know something about dialogs, or something about control structures? What do you want?

When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers cannot speak English...
Anon.

bostonuser
October 17th, 2007, 03:07 PM
I already asked, do you usually construct a program with dialog boxes, if you don't understand the question then that's the problem.

What is not clear? Is the program in front of you not clear? There is a program in the question, there is a switch.

It's pretty clear that I am asking how to construct a program with dialog boxes but I don't want the entire program to be about a dialog box. I want it to do what I wrote it to do.

How is that not clear? Are you unhappy that I want to use dialog boxes? It's not my choice, it's an exercise in a book.

Take it up with the author but I am looking for a way to write a program to do What I want it to DO, that is something useful,
and at the same time use a dialog box or two.

keang
October 17th, 2007, 03:28 PM
I already asked, do you usually construct a program with dialog boxes, if you don't understand the question then that's the problem.Actually this isn't the question you originally asked which was "when you are using control structures such as for loops or switch,
do you write the code using the dialog boxes". These are two totally different questions. As dlorde has already stated the original question makes no sense - control structures and dialog boxes are not at all related to each other and it's possible to write code with either, both in isolation and/or in combination.

To answer your new question: it just depends on what you are trying to do. If you want a GUI and require dialogs then use them, if not don't use them.

Your code use a CLI to get and display the information, if that works for you then leave it as that. If you want to use a GUI to input and display the information then you could do it with dialogs but it would probably be better with a dedicated GUI, for example: a JFrame containing input fields, an output display area and a Calculate and Exit button.

dlorde
October 17th, 2007, 03:42 PM
I already asked, do you usually construct a program with dialog boxes, if you don't understand the question then that's the problem.It's true, I don't understand the question, and that's the problem. To me it looks nonsensical, a non-sequitur. I use dialogs in applications that happen to need them, I don't use them where they are not required. As I keep saying, there is no functional connection between control structures and dialogs, so asking me if I generally use dialogs when I use control structures doesn't make sense.
What is not clear?Your question.
Is the program in front of you not clear?The program is clear.
There is a program in the question, there is a switch.Er, yes....
It's pretty clear that I am asking how to construct a program with dialog boxes but I don't want the entire program to be about a dialog box.Ah, it's certainly clearer now you've actually said what you are asking - except for the bit about not wanting the entire program to be 'about a dialog box'. Can you explain what you mean?

I ask, because the code you posted prompts for a single input then outputs the prompt item matching the input, and then it stops - if you used a dialog for that there wouldn't be anything left to do, so in a sense, the whole program would be 'about that dialog box'. How could it not be?

We seem to be talking to each other from different planets - you want to use dialog boxes, which I understand, but you don't want the program to be about a dialog box, which I don't understand.
I want it to do what I wrote it to do.You wrote it to not use dialog boxes, and it does that.
How is that not clear?It's not clear because I can't make sense of what you're asking.
Are you unhappy that I want to use dialog boxes?Not at all, I'm happy for you to use dialog boxes whenever you want.
It's not my choice, it's an exercise in a book.OK, that's not necessarily a bad thing.

Are you asking how to use a dialog instead of the console to do the input/output in your posted code? If so, what part of using a dialog is giving you trouble?

One day Chao-Chou fell down in the snow, and called out: "Help me! Help Me!" A monk came and lay down beside him. Chao-Chou got up and went away...
Zen koan.