Create a program to mimic the design of Draw Panel Lines Corner in Java. Java GUI and graphics program to create designs using drawline.
Create a program to mimic the design of Draw Panel Lines Corner in Java
/*
* Filename: DrawPanelLinesCorner.java
*
* Description: 4.1 - Create a program to mimic the design of 4.20.
*
*@Author: Bilal Tahir Khan Meo
* Website: https://codeblah.com
*
* =====================================================================================
*/
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanelLinesCorner extends JPanel{
public void paintComponent(Graphics g){
// call paintComponent to ensure correct panel display
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
int wSteps = width / 15;
int hSteps = height / 15;
int xDelta = wSteps;
int yDelta = height;
// draw a series of lines fanning from top corner
for(int i=0; i<15; i++){
g.drawLine(0, 0, xDelta, yDelta);
xDelta ยบ+= wSteps;
yDelta -= hSteps;
}
}
}
DrawPanelLinesCornerTest.java
/*
* Filename: DrawPanelLinesCornerTest.java
*
* Description: 4.1 - DrawPanelLinesCornerTest
*
*@Author: Bilal Tahir Khan Meo
* Website: https://codeblah.com
*
* =====================================================================================
*/
import javax.swing.JFrame;
public class DrawPanelLinesCornerTest{
public static void main(String[] args){
DrawPanelLinesCorner panel = new DrawPanelLinesCorner();
// frame to hold the panel
JFrame application = new JFrame();
// set frame to exit on close
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(250, 250);
application.setVisible(true);
}
}