Created
September 19, 2015 21:26
-
-
Save kpshek/f668b9c578b9a067073d to your computer and use it in GitHub Desktop.
Java2D Example
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
package com.example; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import java.awt.geom.Rectangle2D; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
public class App extends JFrame { | |
private static final long serialVersionUID = -1212074721130125123L; | |
public App() { | |
add(new Gfx()); | |
setTitle("Simple Java 2D example"); | |
setSize(300, 200); | |
setLocationRelativeTo(null); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
} | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
App ex = new App(); | |
ex.setVisible(true); | |
} | |
}); | |
} | |
public class Gfx extends JPanel { | |
private static final long serialVersionUID = -30883400631899767L; | |
@Override | |
public void paintComponent(Graphics g) { | |
super.paintComponent(g); | |
System.out.println("here"); | |
Graphics2D g2 = (Graphics2D) g; | |
g2.setPaint(Color.RED); | |
g2.fill(new Rectangle2D.Double(10, 5, 20, 20)); | |
g2.setPaint(Color.BLACK); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much! This has helped our team so much! Hope you have a good time with all of the presentations tomorrow.