[go: up one dir, main page]

0% found this document useful (0 votes)
52 views6 pages

Sanchez Lesson 1

This document contains an example program written in Java that compares DOS-based and Windows-based programming. It provides 3 samples that display text, prompt for user input, and perform a calculation. The samples are shown first using standard output methods in DOS-based programming and then using dialog boxes in Windows-based programming with Swing. The document also includes an assignment asking the student to create 3 short Java programs using different JOptionPane message types.

Uploaded by

Kent Sanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views6 pages

Sanchez Lesson 1

This document contains an example program written in Java that compares DOS-based and Windows-based programming. It provides 3 samples that display text, prompt for user input, and perform a calculation. The samples are shown first using standard output methods in DOS-based programming and then using dialog boxes in Windows-based programming with Swing. The document also includes an assignment asking the student to create 3 short Java programs using different JOptionPane message types.

Uploaded by

Kent Sanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ITC 120 COMPUTER PROGRAMMING 2

Sanchez, Kent Raziel I.


1st Year BSCS

WRITTEN ACT#1

1. Differentiate Windows from Dialog Box.

- A Windows is a graphical user interface (GUI) element that represents an open application or
document on a computer. It typically includes a title bar, menu bar, and a toolbar. A Window can
be resized, minimized, and closed.

A Dialog Box is a type of window that is used to display information or to receive input from the
user. Dialog boxes are typically used to prompt the user for information or to display important
messages. They often have buttons for the user to interact with, such as "OK" or "Cancel."

2. Compare JOptionPane.showMessageDialog from


JOptionPane.showInputDialog

- JOptionPane.showMessageDialog is a method that displays a modal dialog box


with a message and an OK button, while JOptionPane.showInputDialog is a method that
displays a modal dialog box with a message, an input field, and OK and Cancel buttons, it
returns the text entered by the user in the input field, or null if the user cancels the dialog.

3. Differentiate java Structure Program into Object Oriented


Programming Language.

- Structure programming breaks down a program into smaller procedures and


functions, while OOP like Java uses objects and classes to organize code. OOP has
added concepts such as encapsulation, inheritance, polymorphism and abstraction for
a more organized, efficient and effective way of developing software applications..
LESSON 1: HANDS ON ACTIVITY 1
COMPARISON OF DOF-BASED AND WINDOWS-BASED
SAMPLE 1: DISPLAY SIMPLE TEXT
DOS-BASED WINDOWS-BASED
OUTPUT: OUTPUT:

package sanchez;
public class Sanchez { package sanchez;
public static void main(String[] import javax.swing.*;
args) { public class Sanchez {
System.out.println(" Welcome to public static void main(String[] args)
Java Program"); {
} JOptionPane.showMessageDialog(null
} ,"Welcome to Earth");
}
}
SAMPLE 2: INPUT NAME
DOS-BASED WINDOWS-BASED
OUTPUT: OUTPUT:

package sanchez;
import java.util.Scanner;
public class Sanchez {
public static void main(String[]
args)throws Exception {
Scanner x = new Scanner (System.in);
String name;
System.out.print("Enter your name: ");
name=x.nextLine();
System.out.println("Your name is "+ package sanchez;
name); import javax.swing.*;
public class Sanchez {
} public static void main(String[]
args)throws Exception {
} String putName=
JOptionPane.showInputDialog(n
ull,"Enter your name: ");
JOptionPane.showMessageDialo
g(null,"Your name is" +
putName);
}

}
SAMPLE 3: ADDING TWO NUMBER
DOS-BASED WINDOWS-BASED
OUTPUT: OUTPUT:

package sanchez;
import java.util.Scanner;
public class Sanchez {
public static void main(String[]
args)throws Exception {
Scanner x = new Scanner
(System.in);
int n1,n2,sum;
String num1,num2;
System.out.print("Enter a number:
"); package sanchez;
n1= x.nextInt(); import javax.swing.*;
System.out.print("Enter you public class Sanchez {
public static void main(String[]
Second number: " );
args)throws Exception {
n2= x.nextInt();
int n1,n2,sum;
sum = n1+n2; String num1,num2;
System.out.println("The sum num1 =
is "+ sum); JOptionPane.showInputDialog(null,
"Enter your first number: ");
} n1= Integer.parseInt(num1);
num2=
} JOptionPane.showInputDialog(null,
"Enter your second number: ");
n2= Integer.parseInt(num2);
sum = n1+n2;
JOptionPane.showMessageDialog(n
ull,"The sum is "+ sum);
}

ASSIGNMENT:

Example 1:
package sanchez;
import javax.swing.*;

public class Sanchez {

public static void main(String[] args)throws Exception {


JOptionPane.showMessageDialog(null,"You hate programming but love it",
"Windows Caption",JOptionPane.PLAIN_MESSAGE);

}
Example 2:

package sanchez;
import javax.swing.*;

public class Sanchez {

public static void main(String[] args)throws


Exception {
JOptionPane.showMessageDialog(null,"WRONG PASSCODE",
"Windows Caption",JOptionPane.ERROR_MESSAGE);

Example 3:

package sanchez;
import javax.swing.*;
public class Sanchez {

public static void main(String[] args)throws Exception {


JOptionPane.showMessageDialog(null,"HOLD AND RELEASE",
"Windows Caption",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"YOU DID NOT SAVE ",
"Windows Caption",JOptionPane.WARNING_MESSAGE);

JOptionPane.showMessageDialog(null,"RESET PASSCODE?",
"Windows Caption",JOptionPane.QUESTION_MESSAGE);

You might also like