"Java" random number generator, GObject, event driven

Source: Internet
Author: User

Learning resources from a 2008-year public course at Stanford University


This part of the content is mainly the use of Java for the operation of the drawing, personally think it is quite interesting piece of content, after watching the drum to do a jigsaw puzzles and other small games to play is also possible.


8.
Random number generator:
Private Randomgenerator rgen=randomgenerator.getinstance ();


Method:
int nextint (int low, int. high)--Returns a random number in between
int nextint (int n)--Returns a random number between 0~n-1
Double nextdouble (double low, double high)--Returns a random number D Low<=dDouble nextdouble ()--Returns a random number D 0<=d<1
Boolean Nextboolean ()--the probability of returning true is 50%
Boolean Nextboolean (double p)--the probability of returning to True is P 0<=p<1
Color Nextcolor ()--randomly produces a color
The first value given to a random number counter is called a seed, and the seed determines the sequence of random number generation, typically used to test data
Rgen.setseed (1);--For testing use

Analog Dice:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A9/wKiom1Xqk4fTnt0YAAGjlR2yCJ4170.jpg "title=" 1.png " alt= "Wkiom1xqk4ftnt0yaagjlr2ycj4170.jpg"/>
10-(10),

Super ()--Call the parent class constructor

Acm.graphics--the shapes added to the canvas are stacked sequentially

Gcanvas--Collage Background canvas

the methods that the canvas (Gcanvas) and graphics programs (Graphicsprogram) have:
Add object to the canvas
Add (object,x,y) specifies the display coordinates
Remove (object) removes objects
Getelementat (x, y)-frontmost or null gets object coordinates
Gethidth () Get width
GetHeight () Get height
SetBackground (c)-color setting the canvas background color

a method unique to a graphics program:
Pause (milliseconds)--pause (in milliseconds)
Waitforclick ()--Wait for mouse click event

CObjects General Method:
setlocation (x, y)
Move (dx,dy)-offset
GetX () GetY ()-Returns the x and Y coordinates of an object
Gethidth () getheight ()-Return length and width
Contains (x, y)-returns True (whether there is an object at a particular point)
SetColor (c) getColor ()-set/Get Object color
setvisible (flag)--true/false
IsVisible ()-Returns True if the object is visible visible
Sendtofront () SendToBack ()--Change the z-axis order (first, last)
Sendforward () SendBackward ()--moving an object on the z axis

interface (Interface)--a set of methods--have a set of classes they all have the same set of methods
Fill interface: gfillable--setfilled (flag) isfilled () Setfillcolor (c) Getfillcolor ()
Set Object window: Cresizable--setsize (width,height) setbounds (x,y,width,height)
Scaling interface: Gscalable--scale (SF)-scale scaling scale (Sx,sy)-x,y

character-related lines related to typography:
Baseline (baseline)-the line where the character appears (some characters will be exceeded)-Glide line
String height (height): refers to the distance between two lines of baseline
On-Line (ascent)-refers to the highest character--used when the character is centered
Off-line (decent)-refers to the distance that the character furthest reaches from the baseline

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AA/wKiom1XqtKWgnACFAABeNydoRs4193.jpg "title=" 2.png " alt= "Wkiom1xqtkwgnacfaabenydors4193.jpg"/>

Collage Example:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1XqtMGDD8h7AAG2VrrT5sA244.jpg "title=" 3.png " alt= "Wkiom1xqtmgdd8h7aag2vrrt5sa244.jpg"/>

11-(11),

Gpolygon--draw symmetrical graphs of line segments

Need to have a reference point (imaginary reference point)--usually the center point of the graph

Create an empty polygon
Addvertex (x, y)--Specifies the polygon vertex--x, y is the coordinates relative to the reference point
Addedge (Dx,dy)--Add a vertex related to the previous point

Gcompound--Draw composite graphics--compound several shapes together to become an object

Event Driver (Event-driven Programs)

Listener (Listener)-impot java.awt.event.*;
Addmouselisteners ()
Addkeylisteners ()

Mouse Events:
Mouseclicked (E)--click
Mousepressed (e)--Press the mouse
Mousereleased (e)--Release the mouse
Mousemoved (e)--Mobile Mouse
Mousedragged (E)-Drag by mouse

Keyboard Events:
Keypressed (e)--Press the mouse
Keyreleased (e)--Release the mouse
Keytyped (e)--pressed and released compound

Picture object:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1XqtT2Qw5fbAADT2GcsDRQ594.jpg "title=" 4.png " alt= "Wkiom1xqtt2qw5fbaadt2gcsdrq594.jpg"/>


Draw a diamond (wired according to the order of the vertices, you can adjust the order test):

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A7/wKioL1Xqt3nwopqFAAIACs6I3HU902.jpg "title=" 5.png " alt= "Wkiol1xqt3nwopqfaaiacs6i3hu902.jpg"/>


Mouse Event Monitoring:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A7/wKioL1Xqt4vh9ARVAAF3W-quBjs742.jpg "title=" 6.png " alt= "Wkiol1xqt4vh9arvaaf3w-qubjs742.jpg"/>


Draw a composite graphic: (You can draw the graphic as shown by calling)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AA/wKiom1XqtXLxTPWbAALuAMxVA5k439.jpg "title=" 7.png " alt= "Wkiom1xqtxlxtpwbaaluamxva5k439.jpg"/>














This article from "Not Daze" blog, please make sure to keep this source http://tobeys.blog.51cto.com/10620284/1691590

"Java" random number generator, GObject, event driven

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.