introduction to computing concepts note set 15. joptionpane.showmessagedialog message dialog allows...
TRANSCRIPT
![Page 1: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/1.jpg)
Introduction to Computing ConceptsNote Set 15
![Page 2: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/2.jpg)
JOptionPane.showMessageDialog•Message Dialog•Allows you to give a brief message to the user
•Can be used to give helpful messages, errors, or warnings.
![Page 3: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/3.jpg)
Example
import javax.swing.JOptionPane;
public class Tester {
public static void main (String [] args) {
JOptionPane.showMessageDialog(null, "Hello There!!!");
}
}
![Page 4: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/4.jpg)
JOptionPane.showInputDialog•Pops up a dialog and allows the user to enter a string•Method returns a string
•Can be used to ask for strings or numbers.▫Must convert string version of number to numerical
type
![Page 5: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/5.jpg)
Example
import javax.swing.JOptionPane;
public class Tester { public static void main (String [] args) { String data; data = JOptionPane.showInputDialog(null,
"Please input your name."); System.out.println("Hello“ + data); }}
![Page 6: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/6.jpg)
•Use JOptionPane to get 5 numbers from the user then display to the screen.
public static void main(String [] args) {
![Page 7: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/7.jpg)
Breakout 1
![Page 8: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/8.jpg)
do…while Loop
do //some Java Statementwhile (expression);
do { //some //statements //can go here} while (expression);
single statementno braces
multiple statementsneed braces
![Page 9: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/9.jpg)
Two Types of Loops
do { //some //statements //can go here} while (expression);
VS:
while(expression) { //do something //here}
![Page 10: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/10.jpg)
What is Displayed
int x = 1;while (x < 0) System.out.println(x);
do System.out.println(x);while (x < 0);
![Page 11: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/11.jpg)
What is Displayed?
int c = 10;do { System.out.println(“hello”); c++;} while (c < 4);
![Page 12: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/12.jpg)
What is Displayed?
int v = 0;do { v++; System.out.println(v); } while (v < 4);
![Page 13: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/13.jpg)
What is Displayed?int count = 0;int funny = 1;int serious = 0;int limit = 4;do { funny ++; serious = serious + 2; count = count + 1;} while (count < limit);System.out.println(funny + “ “ + serious + “ “ + count );
![Page 14: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/14.jpg)
QuickCode•Write a snippet of code that asks the user to enter
integers until the sum of the numbers entered is greater than 300. Use a do…while loop
![Page 15: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/15.jpg)
Nested Loops• It is possible to have one looping structure inside
another
int first = 0;int second = 0;while (first < 3) { do { System.out.print(“*”); //doesn’t go to next line second += 1; }while (second < 4); System.out.println(); first += 1; second = 0;}
![Page 16: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/16.jpg)
Breakout 2
![Page 17: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/17.jpg)
17
For Loop
• Ideal for situations that require a counter
•Has built in expressions that initialize and update variables
![Page 18: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/18.jpg)
18
For Loop
for (initialization; test; update)
statement;
for (initialization; test; update){
statement;statement;//Place as many here as needed
}
![Page 19: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/19.jpg)
19
For Loop
for (initialization; test; update)
statement;
Used to set up counter variable
![Page 20: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/20.jpg)
20
For Loop
for (initialization; test; update)
statement;
Controls execution of loop
![Page 21: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/21.jpg)
21
For Loop
for (initialization; test; update)
statement;
Updates (increments) counter variable
![Page 22: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/22.jpg)
22
For Loop
for (int num=0; num<4; num++)
System.out.println(num + “\t” + num*num);
1. Perform initialization of counter
![Page 23: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/23.jpg)
23
for (int num=0; num<4; num++)
System.out.println(num + “\t” + num*num);
For Loop
1. Perform initialization of counter
2. Evaluate test
• if num < 4, go to step 3
• else terminate loop
![Page 24: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/24.jpg)
24
for (int num=0; num<4; num++)
System.out.println(num + “\t” + num*num);
For Loop
1. Perform initialization of counter
2. Evaluate test
3. Execute statement
![Page 25: Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used](https://reader035.vdocuments.mx/reader035/viewer/2022062806/5697bfc91a28abf838ca8fce/html5/thumbnails/25.jpg)
25
for (int num=0; num<4; num++)
System.out.println(num + “\t” + num*num);
For Loop
1. Perform initialization of counter
2. Evaluate test
3. Execute statement
4. Perform update – go back to step 2