This week, I learned graphic programming.
The basic content is: simple graphics frame construction.
Eventqueue.invokelater (()
{
Simpleframe frame = new Simpleframe ();
Frame.settitle ();
Frame.setdefaultcloseoperation (Jframe.exit_on_close);
Frame.setvisible (TRUE);
});
private static String message;
public static String GetMessage () {
return message;
}
Public Simpleframe ()
{
SetSize (Default_width, default_height);
}
Writing of graphical cues: Fra.settitle ("welcome!"); /Window Prompt
Frame positioning:
Set frame width, height and let platform pick
SetSize (SCREENWIDTH/2, SCREENHEIGHT/2);//long, wide, half the screen,
Setlocationbyplatform (TRUE);//determines where the frame is placed.
To display information in the component:
public void Paintcomponent (Graphics g)//Describes methods for drawing components.
{
graphics2d g2 = (graphics2d) g;
Draw a rectangle
Double LEFTX = 100;
Double topy = 100;
Double width = 200;
Double height = 150;.. }
There is also the construction of the graphics in the component:
Public Drawframe ()
{
Add (New Drawcomponent ());//Adds a given component to the contents pane, which is titled Rectangle.
Pack ();//Adjust window size.
}
Rectangle2D rect = new Rectangle2d.double (LEFTX, topy, width, height);
G2.draw (rect);
G2.draw (New Line2d.double (LEFTX, topy, Leftx + width, topy + height);//. The position and height of the upper left corner.
Multiple windows can be generated, but not multi-layered.
201671010131 2016-2017-2 "Java Programming"