![]() You will need the lwjgl natives and lwjgl binary for your system to run this. This game is not finished and may never be. However, I suck at using the LWJGL so that will have to wait. This was going to to have circles instead of the squares. JFrame f = new JFrame("Draw a rectangle") į.getContentPane().add(new DrawMyRect()) į.setDefaultCloseOperation(JFrame. A simple game written in Java and using the LWJGL for drawing. Here is the program that draws a rectangle on the screen. The width and height of the square must be identical. The first two parameters specify the starting point and the last two parameters specify the width and height of the rectangle or square. Graphics class provides the Graphics.drawRect(int x, int y, int width, int height) method for drawing a rectangle or square. import į.getContentPane().add(new DrawM圜ercle()) Here is the program that draws a circle on the screen. For the circle, set the same width and height. ‘x’ and ‘y’ are the starting point on the screen, and ‘width’ and ‘height’ are the parameters to set the width and height of the oval or circle. You can draw a circle and oval using the Graphics.drawOval(int x, int y, int width, int height) method. ![]() ![]() import į.getContentPane().add(new DrawMyLine()) į.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) Similarly, x2 and y2 are the coordinates of the second point in the line. While x1 is the x-coordinate of the first point in the line and y1 is the y-coordinate of the first point in the line. ![]() Graphics class provides the Graphics.drawline(int x1, int y1, int x2, int y2) method to draw a line on the screen. Java offers us an easy way to draw graphics using Graphics class in AWT package which allows us to draw primitive geometric types like lines, circles, etc… This tutorial explains the different functions of Graphics class used to draw shapes. In this tutorial, we are going to see how to draw lines, rectangles and circles in JFrame. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |