Informaticasite van het Sondervick College te Veldhoven                 © L.J.M van Haperen (bron : R.J. van der Beek)
 

Hoofdstuk 18.9. Overzicht

 18.9.1 De primitieve typen

byte 8-bit integers (-128 tot 127)
short 16-bit integers(-32768 tot 32767)
int 32-bit integers (-2.147.483.648 tot 2.147.483.647)
long 64-bit integers (-9.223.372.036.854.775.808 tot 9.223.372.036.854.775.807)
float 32-bit kommma-getallen(1,40129846432481707e-45 tot 3,40282346638528860e+38)
double 64-bit komma-point getallen(4,94065645841246544e-324 tot 1,79769313486231570e+308)
char 16-bit Unicode karakters
boolean true of false

primitieve typen horen niet bij een bepaalde klasse. Er horen dan ook geen methoden bij.

Als je een bepaalde klasse gebruikt moet je die eerst declareren.
Bijvoorbeeld Label lHallo;
Dan moet je een instantie creëren. Bijvoorbeeld lHallo=new Label( );
(je mag dit ook combineren tot één opdracht: Label lHallo=new Label( );
Daarna pas mag je methoden van die klasse gebruiken.
Bijvoorbeeld: lHallo.setText("Hallo");

Uitzonderingen hierop:
Bij Strings en primitieve typen hoef je het woord new niet te gebruiken.
Je kunt bijv. bij strings de volgende opdracht geven String t="Hallo";
(het mag ook wel zo: String t=new String("Hallo"); )
Bij getallen gaat het bijv. zo: int k=3;

Arrays
Stel je wilt 1000 keer met een dobbelsteen gooien, en dan vastleggen hoe vaak er een 1, 2, 3, 4, 5 en 6 gegooid is. Dan kun je handig gebruik maken van een array.
Het aantal enen kun je bewaren in aantal[1], het aantal tweeën in aantal[2], enz.
Een array van integers, die je aantal noemt, declareer je zo: int [] aantal;
Daarna moet de array gecreëerd worden, dat gaat zo: aantal = new int[7];
(dan kun je gebruik maken van aantal[0] t/m aantal[6])
De vorige twee pdrachten kun je tot één opdracht combineren: int[] aantal = new int[7];
Daarna kun je beginwaarden geven op de volgende manier:
for (int i=0; i<7; i++) { aantal[i]=0; }

Een opdracht, waar je bij arrays ook gebruik van kunt maken:
getLength(aantal); geeft de lengte van de array, d.w.z. het aantal elementen dat een waarde heeft gekregen.

Escapecodes
Er bestaan escapecodes om speciale tekens op het scherm te brengen:

escapecodebetekenis
\'enkel aanhalingsteken
\"dubbel aanhalingsteken
\\backslash
\bbackspace
\dddoctaal teken
\fformfeed - nieuwe pagina
\nnewline (line feed)
\rcarriage return (nieuwe regel)
\ttabulator
\uxxxxhexadecimaal Unicode-teken


Operatoren

Operator Betekenis VoorbeeldUitkomst
+ Optelling3 + 4 7
- Aftrekken5 - 7 -2
* Vermenigvuldiging5 * 5 25
/ Delen14 / 7 2
% Modulo (= rest)15 % 4 3
+= x = x + yx += y 
-= x = x - yx -= y 
*= x = x * yx *= y 
/= x = x / yx /= y 
==gelijk aan x == 3 
!= niet gelijk aanx != 3  
< kleiner danx < 3  
> groter danx > 3  
<= kleiner of gelijkx <= 3  
>= groter of gelijkx >= 3  
++ Incrementiex++x = x + 1
-- Decrementiex--x = x - 1

 18.9.2 Conversie

Als je een getal moet omzetten naar een string dan kan dat m.b.v. een toString()-methode.
Afhankelijk van het type moet je gebruik maken van:
  • Integer.toString(i); (kan ook met IntToStr(i); )
  • Double.toString(d);
  • Boolean.toString(b);
  • Character.toString(c); enz
Je kunt ook gebruik maken van de methode String.valueOf(v);
Daarbij kan v een integer, double, float, boolean, enz zijn.

Het omgekeerde kan ook, een string omzetten in een getal.
Dat kan m.b.v. een parseXxx-methode; afhankelijk van het type moet je gebruik maken van:
  • Integer.parseInt(s); (kan ook met StrToInt(s); )
  • Float.parseFloat(s);
  • Double.parseDouble(s); enz.
Het kan ook door gebruik te maken van casten (zie volgende alinea)
Bijvoorbeeld: String s1 = "" + i;

Casten
Bij Java is het vaak nodig om een variabele van het ene type naar het andere om te zetten, casten noem je dat.
Soms gebeurt dat ook automatisch, kijk naar het volgende voorbeeld:
byte b = 30;
int i;
i = b;

In dit voorbeeld wordt in de laatste opdracht een byte naar een integer gecast.
Java zal een variabele automatisch laten veranderen van type als aan de volgende voorwaarden voldaan zijn:
  • Het gegevenstype en de variabeletypen zijn compatibel
  • Het doeltype heeft een groter bereik dan het brontype
Expliciete typeconversie
Wanneer het doeltype een kleiner bereik heeft dan het brontype dan moet je het gegevenstype expliciet omzetten: je moet zelf aangeven dat je het type wenst te veranderen. Doe je dit niet, dan krijg je een 'possible loss of precision'-fout. Kijk naar het volgende voorbeeld:
int i = 30;
byte b;
b = (byte) i;

Er is een cast nodig in Java als er informatie verloren dreigt te gaan, zoals in de volgende regels:
double a = 10, double b = 5;
int c = a / b;

Deze regels geven een foutmelding. Weliswaar is 10/5 gelijk aan 2, maar een deling tussen twee variabelen van het type double levert vaak een gebroken getal op, en daar gaat Java dan ook vanuit. We moeten de compiler duidelijk maken dat het geen vergissing door er nog eens extra (int) tussen haakjes voor te zetten:
int c = (int) a/b;

Deze cast is niet nodig als a en b allebei van het type int zijn. Java geeft bij deling van twee variabelen van het type int namelijk altijd een geheel getal als uitkomst, zoals bij de volgende deling:
int a = 5, b = 2;
double c = a / b;

Je zou misschien de waarde 2.5 verwachten. Maar de berekende waarde van c blijkt 2 te zijn, als is c als double gedeclareerd.
Delen van twee int-variabelen geeft in Java standaard altijd als uitkomst een geheel getal. Wil je kommagetal als uikomst, dan moet je Java duidelijk maken dat een van de twee betrokken getallen als kommagetal moet worden beschouwd. Of je moet zorgen voor een expliciete typeconversie door (double) tussen haakjes voor de berekening te zetten. Dus zo:
int a = 5;
double b = 2;
double c = a / b;

Of zo:
int a = 5, b = 2;
double c = (double)a / b;

Commentaar
Er zijn twee soorten commentaar in java:
  • Achter //
    Alles wat op een regel achter // staat wordt door de compiler genegeerd, dus als commentaar gerekend.
  • Tussen /** en */
    Als het commentaar uit meer dan één regel bestaat gebruik je dit meestal.
    Alles wat tussen /** en */ staat wordt door java als commentaar gerekend.
Een voorbeeld waarbij de twee stijlen van commentaar gebruikt worden:

/** De volgende drie programmaregels
*     verwisselen de inhoud van x en y
*     door gebruik te maken van een
*     hulpveranderlijke temp.
*/
temp = x;   // bewaar de oude inhoud van x
x = y;         // vervang x door de inhoud van y
y = temp;   // vervang y door de vorige inhoud van x

 18.9.3 Controlestructuren

Selectie statements

De selectie statements (een statement is een ander woord voor opdracht) if, if-else en switch maken het mogelijk om keuzes te kunnen maken in java-code.
  • Het if statement:

    if (  voorwaarde   )
    {
            ...........
    }

  • Het if-else statement:

    if (  voorwaarde   )
    {
            ...........
    }
    else
    {
            ...........
    }

  • Je kunt de if-else statements ook nesten op de volgende manier:

    if (  voorwaarde   )
    {
            ...........
    }
    else if (  voorwaarde   )
    {
            ...........
    }
    else if (  voorwaarde   )
    {
            ...........
    }
    else
    {
            ...........
    }

  • Het switch statement:

    switch ( variabele )
    {
        case waarde1:
             { ...............
                break; }
        case waarde2:
             { ...............
                break; }
        default:
             { ...............
                break; }
    }

    Als de switch-variabele geen enkele van de genoemde waarden aanneemt dan wordt het opdrachtenblok van default uitgevoerd.
    De default-opdracht is niet verplicht.
    De break-opdracht is ook niet verplicht, maar zonder de break-opdracht wordt de rest van het hele switch-opdrachtenblok uitgevoerd, al neemt de variabele de overige waarden niet aan (dat wordt fall-through genoemd).
    Met de break-opdracht spring je uit het switch-blok.
Samengestelde voorwaarde
Je kunt ook samengestelde voorwaarden gebruiken in de voorwaarde bij een if-opdracht.
  • Als er aan beide voorwaarden moet zijn voldaan dan gebruik je && (De logische bewerking EN)
  • Als er aan één van beide voorwaarden moet zijn voldaan dan gebruik je || (De logische bewerking OF)
  • Als twee waarden gelijk moeten zijn dan gebruik je == (is gelijk aan)
  • Als twee waarden niet gelijk moeten zijn dan gebruik je != (is niet gelijk aan)
De volgende uitdrukking geeft bijvoorbeeld aan dat a ongelijk aan 3 en ongelijk aan 4 moet zijn, of dat b kleiner of gelijk aan a is:
(a != 3 && a != 4) || b <= a
De logische bewerking EN heeft een hogere prioriteit dan de logische bewerking OF, dus de haakjes mag je hier ook weglaten.

Herhaal statements
De herhaal statements zijn while, for en do-while
Ze zorgen er voor dat hetzelfde stukje code steeds wordt herhaald (dat noem je een loop) totdat niet meer aan de herhaal-voorwaarde wordt voldaan.
  • Het while statement:

    while (  voorwaarde   )
    {   ...........   }

  • Het for statement:

    for (  beginwaarde; voorwaarde;   volgende waarde)
    {   ...........   }

  • Het do-while statement:

    do
    {   ...........   }
    while (  voorwaarde;   )

 18.9.4 Uitzonderingen

Met de try-catch-finally statement kun je mogelijke fouten afvangen en omzetten in foutmeldingen voor de gebruiker.
Ook kan dit worden gebruikt om fouten te onderdrukken en vervolgens iets totaal anders te gaan doen.
De risicoinstructie zet je in een try{ ... }-blok.
Uitzonderingen vang je op in een catch( fouttype variabelenaam ){ ... }-blok.

Het try-catch-finally statement:

try
{
        ...........
}
catch (   fouttype1 variabale1   )
{
        ...........
}
catch (   fouttype2 variabale2   )
{
        ...........
}
catch (   fouttype3 variabale3   )
{
        ...........
}
finally
{
        ...........
}

Het try-statement heeft op z'n minst éé catch- of finally-statement nodig.
Je kunt meerdere catch-blokken invoeren, afhankelijk van het fouttype.
Als je een catch-statement hebt dan mag je de finally-statement weglaten.

Als er in de try-opdracht een fout optreedt, dan wordt er binnen de catch-blokken gezocht naar het fout-type.
Als deze wordt gevonden, dan worden de bijbehorende opdrachten van het catch-blok uitgevoerd. Alle overige catch-blokken worden dan overgeslagen.
Als er een finally-statement aanwezig is dan wordt deze altijd uitgevoerd, ongeacht het resultaat van de try-opdracht.

 18.9.5 De klasse Component.

De klassen Button, TextField, Label, List, enz. hebben allemaal ook deze methoden die horen bij Component. Ze komen allemaal uit de package java.awt

De belangrijkste methoden zijn:
requestFocus( ) Requests the input focus.
setBackground(Color)Sets the background color.
setBounds(int xpos, int ypos, int width, int height) Reshapes the Component to the specified bounding box.
setEnabled(boolean)Enables a component.
setFont(Font)Sets the font of the component.
setForeground(Color)Sets the foreground color.
setLocation(int xpos, int ypos)Moves the Component to a new location.
setName(String)Sets the name of the component to the specified string.
setSize(int width, int height) Resizes the Component to the specified width and height.
setVisible(boolean)Shows or hides the component depending on the boolean flag b.
transferFocus( )Transfers the focus to the next component.

 18.9.6 De klasse Button

getLabel( ) Gets the label of the button.
setLabel(String) Sets the button with the specified label.

 18.9.7 De klasse Label

getAlignment( ) Gets the current alignment of this label.
getText( ) Gets the text of this label.
setAlignment(int alignment) Sets the alignment for this label to the specified alignment.
setText(String) Sets the text for this label to the specified text.

 18.9.8 De klasse TextField

getSelectedText( ) Returns the selected text contained in this TextComponent.
getSelectionEnd( ) Returns the selected text's end position.
getSelectionStart( ) Returns the selected text's start position.
getText( ) Returns the text contained in this TextComponent.
isEditable( ) Returns the boolean indicating whether this TextComponent is editable or not.
select(int, int) Selects the text found between the specified start and end locations.
selectAll( ) Selects all the text in the TextComponent.
setCaretPosition(int) Sets the position of the text insertion caret for the TextComponent
setEditable(boolean) Sets the specified boolean to indicate whether or not this TextComponent should be editable.
setSelectionEnd(int) Sets the selection end to the specified position.
setSelectionStart(int) Sets the selection start to the specified position.
setText(String) Sets the text of this TextComponent to the specified text.
setColumns(int) Sets the number of columns in this TextField.
setEchoChar(char) Voor wachtwoorden, bijvoorbeeld sterretje in plaats van letters

 18.9.9 De klasse TextArea

TextArea()Constructs a new text area with the empty string as text.
TextArea(int rows, int columns)Constructs a new text area with the specified number of rows and columns and the empty string as text.
void append(String str)Appends the given text to the text area's current text.
getAccessibleContext()Returns the AccessibleContext associated with this TextArea.
int getColumns()Returns the number of columns in this text area.
int getRows()Returns the number of rows in the text area.
int getScrollbarVisibility() Returns an enumerated value that indicates which scroll bars the text area uses.
void insert(String str, int pos)Inserts the specified text at the specified position in this text area.
void replaceRange(String str, int start, int end) Replaces text between the indicated start and end positions with the specified replacement text.
void setColumns(int columns)Sets the number of columns for this text area.
void setRows(int rows) Sets the number of rows for this text area.

 18.9.10 De klasse List

add(String) Adds the specified item to the end of scrolling list.
add(String, int) Adds the specified item to the scrolling list at the specified position.
delItem(int) Removes an item from the list.
deselect(int) Deselects the item at the specified index.
getItem(int) Gets the item associated with the specified index.
getItemCount( ) Returns the number of items in the list.
getItems( ) Returns the items in the list.
getMinimumSize( ) Returns the minimum dimensions needed for the list.
getMinimumSize(int) Returns the minimum dimensions needed for the amount of rows in the list.
getRows( ) Returns the number of visible lines in this list.
getSelectedIndex( ) Get the selected item on the list or -1 if no item is selected.
getSelectedIndexes( ) Returns the selected indexes on the list.
getSelectedItem( ) Returns the selected item on the list or null if no item is selected.
getSelectedItems( ) Returns the selected items on the list in an array of Strings.
isIndexSelected(int) Returns true if the item at the specified index has been selected; false otherwise.
remove(int) Removes an item from the list.
remove(String) Remove the first occurrence of item from the list.
removeAll( ) Removes all items from the list.
replaceItem(String, int) Replaces the item at the given index.
select(int) Selects the item at the specified index.
setMultipleMode(boolean) Sets whether this list should allow multiple selections or not.

 18.9.11 De klasse Scrollbar

ScrollbarConstructs a new vertical scroll bar.
Scrollbar(int orientation, int value, int visible, int minimum, int maximum)Constructs a new scroll bar with the specified orientation, initial value, visible amount, and minimum and maximum values.
addAdjustmentListenerAdds the specified adjustment listener to receive instances of AdjustmentEvent from this scroll bar.
addNotify()Creates the Scrollbar's peer.
getAccessibleContextGets the AccessibleContext associated with this Scrollbar.
getAdjustmentListenersReturns an array of all the adjustment listeners registered on this scrollbar.
getBlockIncrementGets the block increment of this scroll bar.
getLineIncrementVerouderd. replaced by getUnitIncrement().
getListeners  listenerType)Returns an array of all the objects currently registered as Listeners upon this Scrollbar.
getMaximumGets the maximum value of this scroll bar.
getMinimumGets the minimum value of this scroll bar.
getOrientationReturns the orientation of this scroll bar.
getPageIncrementVerouderd.  replaced by getBlockIncrement().
getUnitIncrementGets the unit increment for this scrollbar.
getValueGets the current value of this scroll bar.
getValueIsAdjustingReturns true if the value is in the process of changing as a result of actions being taken by the user.
getVisibleVerouderd.  replaced by getVisibleAmount().
getVisibleAmountGets the visible amount of this scroll bar.
paramStringReturns a string representing the state of this Scrollbar.
processAdjustmentEventAdjustmentEventProcesses adjustment events occurring on this scrollbar by dispatching them to any registered AdjustmentListener objects.
processEvent AWTEventProcesses events on this scroll bar.
removeAdjustmentListener AdjustmentListenerRemoves the specified adjustment listener so that it no longer receives instances of AdjustmentEvent from this scroll bar.
setBlockIncrementSets the block increment for this scroll bar.
setLineIncrementVerouderd.  replaced by setUnitIncrement(int).
setMaximum(int newMaximum)Sets the maximum value of this scroll bar.
setMinimum(int newMinimum)Sets the minimum value of this scroll bar.
setOrientation(int orientation)Sets the orientation for this scroll bar.
setPageIncrementVerouderd.  replaced by setBlockIncrement().
setUnitIncrementSets the unit increment for this scroll bar.
setValue(int newValue)Sets the value of this scroll bar to the specified value.
setValueIsAdjusting(boolean b)Sets the valueIsAdjusting property.
setValues(int value, int visible, int minimum, int maximum)Sets the values of four properties for this scroll bar: value, visibleAmount, minimum, and maximum.
setVisibleAmount(int newAmount)Sets the visible amount of this scroll bar.

 18.9.12 De klasse String

Deze klasse komt uit de package java.lang
Dit package hoeft als enige niet geimporteerd te worden, hij is standaard aanwezig

charAt(int) Returns the character at the specified index.
compareTo(String) Compares two strings lexicographically.
concat(String) Concatenates the specified string to the end of this string.
endsWith(String) Tests if this string ends with the specified suffix.
equals(Object) Compares this string to the specified object.
equalsIgnoreCase(String) Compares this String to another object.
indexOf(int character) Returns the index within this string of the first occurrence of the specified character.
indexOf(int character, int) Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
indexOf(String) Returns the index within this string of the first occurrence of the specified substring.
indexOf(String, int) Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
lastIndexOf(int character) Returns the index within this string of the last occurrence of the specified character.
lastIndexOf(int, int) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.
lastIndexOf(String) Returns the index within this string of the rightmost occurrence of the specified substring.
lastIndexOf(String, int) Returns the index within this string of the last occurrence of the specified substring.
length( ) Returns the length of this string.
replace(char, char) Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
startsWith(String) Tests if this string starts with the specified prefix.
startsWith(String, int) Tests if this string starts with the specified prefix.
substring(int) Returns a new string that is a substring of this string.
substring(int, int) Returns a new string that is a substring of this string.
toLowerCase( ) Converts this String to lowercase.
toUpperCase( ) Converts this string to uppercase.
trim( ) Removes white space from both ends of this string.
valueOf(boolean) Returns the string representation of the boolean argument.
valueOf(char) Returns the string representation of the char * argument.
valueOf(getal : int of float of double of long) Returns the string representation of the getal argument.

 18.9.13 De klasse Graphics

Deze klasse komt uit de package java.awt

clearRect(int, int, int, int) Clears the specified rectangle by filling it with the background color of the current drawing surface.
clipRect(int, int, int, int) Intersects the current clip with the specified rectangle.
copyArea(int, int, int, int, int, int) Copies an area of the Component by a distance specified by dx and dy to the right and down.
create( ) Creates a new Graphics object that is a copy of this Graphics object.
draw3DRect(int, int, int, int, boolean) Draws a 3-D highlighted outline of the specified rectangle.
drawArc(int, int, int, int, int, int) Draws the outline of an arc covering the specified rectangle, starting at startAngle and extending for arcAngle degrees, using the current color.
drawImage(Image, int, int, Color, ImageObserver) Draws as much of the specified image as is currently available at the specified coordinate (x, y) with the given solid background color.
drawLine(int, int, int, int) Draws a line between the coordinates (x1,y1) and (x2,y2) using the current color.
drawOval(int, int, int, int) Draws the outline of an oval covering the specified rectangle using the current color.
drawRect(int, int, int, int) Draws the outline of the specified rectangle using the current color.
drawRoundRect(int, int, int, int, int, int) Draws the outline of the specified rounded corner rectangle using the current color.
drawString(String, int, int) Draws the specified String using the current font and color.
fill3DRect(int, int, int, int, boolean) Paints a 3-D highlighted rectangle filled with the current color.
fillArc(int, int, int, int, int, int) Fills an arc bounded by the specified rectangle, starting at startAngle and extending for arcAngle degrees, with the current color.
fillOval(int, int, int, int) Fills an oval bounded by the specified rectangle with the current color.
fillRect(int, int, int, int) Fills the specified rectangle with the current color.
fillRoundRect(int, int, int, int, int, int) Fills the specified rounded corner rectangle with the current color.
getColor( ) Gets the current color.
getFont( ) Gets the current font.
setColor(Color) Sets the current color to the specified color.
setFont(Font) Sets the font for all subsequent text rendering operations.
setPaintMode( ) Sets the logical pixel operation function to the Paint, or overwrite mode.
setXORMode(Color) Sets the logical pixel operation function to the XOR mode, which alternates pixels between the current color and a new specified XOR alternation color.

 18.9.14 De klasse Color

Deze klasse komt uit de package java.awt

Als kleurnamen kun je gebruiken:
black, blue , cyan , darkGray, gray , green , lightGray, magenta , orange , pink , red , white , yellow

Constructor:
Color(int, int, int) : Creates a color with the specified red, green, and values in the range (0 - 255).

Methoden:
brighter( ) Returns a brighter version of this color.
darker( ) Returns a darker version of this color.
getBlue( ) Gets the blue component.
getGreen( ) Gets the green component.
getRed( ) Gets the red component.

 18.9.15 De klasse Font

Deze klasse komt uit de package java.awt

Als style kun je gebruiken: BOLD, ITALIC , PLAIN

Constructor:
Font(String, int, int) : Creates a new font with the specified name, style and point size.

Methoden:
getSize( ) Gets the point size of the font.
getStyle( ) Gets the style of the font.
isBold( ) Returns true if the font is bold.
isItalic( ) Returns true if the font is italic.
isPlain( ) Returns true if the font is plain.

 18.9.16 De klasse Math

Deze klasse komt uit de package java.lang

Math.Ee en Math.PI geven het getal e en het getal pi

Methoden:
abs(getal: double of float of int of long) Returns the absolute value of a the value.
acos(double) Returns the arc cosine of an angle, in the range of 0.0 through pi.
asin(double) Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
atan(double) Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
ceil(double) Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.
cos(double) Returns the trigonometric cosine of an angle.
exp(double) Returns the exponential number e (i.e., 2.718...) raised to the power of a double value.
floor(double) Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
log(double) Returns the natural logarithm (base e) of a double value.
max(getal, getal) Returns the greater of two values.
min(getal,getal) Returns the smaller of two values.
pow(double, double) Returns of value of the first argument raised to the power of the second argument.
random( ) Returns a random number between 0.0 and 1.0.
rint(double) returns the closest integer to the argument.
round(double) Returns the closest long to the argument.
round(float) Returns the closest int to the argument.
sin(double) Returns the trigonometric sine of an angle.
sqrt(double) Returns the square root of a double value.
tan(double) Returns the trigonometric tangent of an angle.

 18.9.17 De klasse Date

Deze klasse komt uit de package java.util

getYear( ) Returns the year represented by this date, minus 1900.
getDay( ) Returns the day of the week represented by this date.
getHours( ) Returns the hour represented by this date.
getMinutes( ) Returns the number of minutes past the hour represented by this date.
getMonth( ) Returns the month represented by this date.
getSeconds( ) Returns the number of seconds past the minute represented by this date.
getTime( ) Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.

  18.9.18 De klasse JOptionPane met methoden voor messageboxen

Deze klasse komt uit de package javax.swing

showMessageDialog(String)Laat een boodschap zien met alleen een OK-knop.
showInputDialog(String)Toont een boodschap en vraagt om invoer. De methode levert een string op, namelijk de invoer
showConfirmDialog(String)Laat een boodschap zien met een Yes- en een No-knop. De methode levert een getal op: 1 als je op Yes hebt gedrukt en anders 0
showOptionDialog(String)Laat een boodschap zien, en je kunt zelf bepalen welke knoppen verder verschijnen. Je kunt o.a. kiezen uit YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION. methode levert een getal op: 1 als je op Yes hebt gedrukt en anders 0

Voorbeeld:
int n = JOptionPane.showConfirmDialog(null,"Wil je meer weten van Java?","lcinformatica.nl",JOptionPane.YES_NO_OPTION);
Het volgende venstertje verschijnt:

message

Een precieze beschrijving van de mogelijkheden vind je op download.oracle.com/javase/tutorial/uiswing/components/dialog.html