Created
March 12, 2013 15:41
-
-
Save figengungor/5143967 to your computer and use it in GitHub Desktop.
Java GUI >> Basic Shapes with Graphics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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