Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created March 9, 2013 20:49
Show Gist options
  • Save figengungor/5125697 to your computer and use it in GitHub Desktop.
Save figengungor/5125697 to your computer and use it in GitHub Desktop.
Java GUI >> Draw a Rectangle
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;
public class MyGUI extends JFrame
{
public MyGUI()
{
setTitle("Tutorial");
setSize(960,960);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.drawRect(480, 480, 200, 100);
g.setColor(Color.BLUE);
g.fillRect(240, 240, 200, 100);
}
public static void main(String[] args)
{
MyGUI frame = new MyGUI();
frame.paint(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment