Skip to content

Instantly share code, notes, and snippets.

@fernandozamoraj
Created February 23, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandozamoraj/74483ac9ae4be1582f4e2aeba9ff6f4c to your computer and use it in GitHub Desktop.
Save fernandozamoraj/74483ac9ae4be1582f4e2aeba9ff6f4c to your computer and use it in GitHub Desktop.
import java.awt.*;
class Window extends Frame{
Window(){
setSize(800,900);//frame size 300 width and 300 height
setLayout(null);//no layout manager
setVisible(true);//now frame will be visible, by default not visible
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
//draw an orange line
g.setColor(Color.ORANGE);
g.drawLine(10,200,400,200);
//draw a circle
g.fillOval(100, 100, 200, 200);
//change color to red
g.setColor(Color.RED);
//draw filled rectangle
g.fillRect(10, 300, 400, 40);
//change color to green and draw another rectangle
g.setColor(Color.GREEN);
g.fillRect(100, 300, 200, 100);
//draw another rectangle
g.drawRect(100, 450, 300, 30);
//create points to form a hexagon
//draw the hexago
int[] xPoints = {210, 240, 280, 310, 280, 240, 210};
int[] yPoints = {600, 550, 550, 600, 650, 650, 600};
g.drawPolygon(xPoints, yPoints, 7);
}
public static void main(String args[]){
Window w=new Window();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment