Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created March 12, 2013 15:41
Show Gist options
  • Select an option

  • Save figengungor/5143967 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/5143967 to your computer and use it in GitHub Desktop.
Java GUI >> Basic Shapes with Graphics
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyGUI extends JPanel{
public void paintComponent(Graphics g)
{
//super.paintComponent(g);
g.setColor(Color.RED);
g.drawRect(100, 50, 30, 20);
g.setColor(Color.GREEN);
g.drawOval(100, 100, 50, 50);
}
public static void main(String [] args) {
MyGUI mygui = new MyGUI(); //Because this class extends JPanel, mygui is a panel object
JFrame jf = new JFrame();
jf.setSize(300,300);
jf.setTitle("Basic Shapes");
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(mygui);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment