Using JOptionPane for input and output - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Using JOptionPane for input and output

Description:

Declare two functions with same name but different arguments to make ... Put ABC.java file in a folder named something. Compile normally. Creating sub-packages ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 26
Provided by: bas44
Category:

less

Transcript and Presenter's Notes

Title: Using JOptionPane for input and output


1
Using JOptionPane for input and output
2
JOptionPane
  • Resides in javax.swing package
  • Used for showing different kind of dialog boxes

3
Displaying Messageboxes
  • Following line of code displays a simple
    messagebox
  • JOptionPane.showMessageDialog( null,
  • Message Title,
  • Message text,
  • JOptionPane.PLAIN_MESSAGE)

4
JOptionPane.showMessageDialog( null, Message
Title, Message text, JOptionPane.PLAIN_ME
SSAGE)
  • Argument 1 Parent Component
  • Argument 2
  • Argument 3

5
Argument 4
  • JOptionPane.PLAIN_MESSAGE

6
Argument 4
  • JOptionPane.QUESTION_MESSAGE

7
Argument 4
  • JOptionPane.WARNING_MESSAGE

8
Argument 4
  • JOptionPane.INFORMATION_MESSAGE

9
Argument 4
  • JOptionPane.ERROR_MESSAGE

10
Taking Input
  • String s
  • s JOptionPane.showInputDialog( Enter a
    number)

11
  • Always returns a string
  • Blocks for input
  • Convert the String s to an integer by
  • int i Integer.parseInt( s )

12
(No Transcript)
13
Lets get Object Oriented
  • Introduction to classes
  • class Name
  • Name() // Constructor

14
Lets get Object Oriented
  • Every class has a method named exactly same as
    the class, called Constructor
  • If you dont define one, a default constructor is
    automatically created, for example for class
    named Name, default constructor looks like
  • Name()

15
Lets get Object Oriented
  • For every class, you can have multiple
    constructors with different arguments (but
    obviously the same name)
  • class Name
  • Name()
  • Name(String s)

16
Class member functions
  • class Name
  • Name() // Constructor
  • public void memberFunc(int x)
  • // Body here

17
Copy Constructor
  • class Name
  • int a, b, c
  • Name(final Name n)
  • a n.a
  • b n.b
  • c n.c

18
Using Copy Constructor
  • class Test
  • public static void main(String a)
  • Name n new Name()
  • Name m new Name(n)

19
Member functions
  • All member functions along with their bodies must
    be typed inside the class code.
  • There is no concept of inline functions in java
  • There is no concept of prototypes either

20
Method Overloading
  • Member function overloading in Java is similar to
    that of C
  • Declare two functions with same name but
    different arguments to make them overloaded

21
Method Overloading Example
  • class Name
  • public myMethod()
  • public myMethod(String s)

22
Recursion
  • Calling a function from within itself is called
    recursion
  • Recursion is allowed in Java as it is in C

23
Recursion Example
  • class Recursive
  • public int function(int i)
  • if(i1 i0)
  • return 1
  • else
  • return i function(i-1)

24
Creating Packages
  • package something
  • class ABC
  • Associates ABC in package something
  • Put ABC.java file in a folder named something
  • Compile normally

25
Creating sub-packages
  • package something.anything
  • class XYZ
  • Associates XYZ in package something.anything
  • Put XYZ.java file in a folder named anything
    placed inside another folder something
  • Compile normally
Write a Comment
User Comments (0)
About PowerShow.com