| Informaticasite van het Lauwers College te Buitenpost © R.J. van der Beek | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
Operatoren
Als je een getal moet omzetten naar een string dan kan dat m.b.v. een
toString()-methode. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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| Scrollbar | Constructs 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. |
| addAdjustmentListener | Adds the specified adjustment listener to receive instances of AdjustmentEvent from this scroll bar. |
| addNotify() | Creates the Scrollbar's peer. |
| getAccessibleContext | Gets the AccessibleContext associated with this Scrollbar. |
| getAdjustmentListeners | Returns an array of all the adjustment listeners registered on this scrollbar. |
| getBlockIncrement | Gets the block increment of this scroll bar. |
| getLineIncrement | Verouderd. replaced by getUnitIncrement(). |
| getListeners listenerType) | Returns an array of all the objects currently registered as Listeners upon this Scrollbar. |
| getMaximum | Gets the maximum value of this scroll bar. |
| getMinimum | Gets the minimum value of this scroll bar. |
| getOrientation | Returns the orientation of this scroll bar. |
| getPageIncrement | Verouderd. replaced by getBlockIncrement(). |
| getUnitIncrement | Gets the unit increment for this scrollbar. |
| getValue | Gets the current value of this scroll bar. |
| getValueIsAdjusting | Returns true if the value is in the process of changing as a result of actions being taken by the user. |
| getVisible | Verouderd. replaced by getVisibleAmount(). |
| getVisibleAmount | Gets the visible amount of this scroll bar. |
| paramString | Returns a string representing the state of this Scrollbar. |
| processAdjustmentEventAdjustmentEvent | Processes adjustment events occurring on this scrollbar by dispatching them to any registered AdjustmentListener objects. |
| processEvent AWTEvent | Processes events on this scroll bar. |
| removeAdjustmentListener AdjustmentListener | Removes the specified adjustment listener so that it no longer receives instances of AdjustmentEvent from this scroll bar. |
| setBlockIncrement | Sets the block increment for this scroll bar. |
| setLineIncrement | Verouderd. 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. |
| setPageIncrement | Verouderd. replaced by setBlockIncrement(). |
| setUnitIncrement | Sets 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| 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| 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| 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| 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| 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| 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| 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 |
