Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.EventQueue;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5.  
  6. import javax.swing.JComponent;
  7. import javax.swing.JFrame;
  8.  
  9. public class Main extends JFrame {
  10.  
  11. public Main(){
  12. initUI();
  13. }
  14.  
  15. private void initUI() {
  16. add(new Canvas());
  17. setTitle("Simple Java 2D");
  18. setSize(800, 600);
  19. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. setLocationRelativeTo(null);
  21. }
  22.  
  23. public static void main(String[] args){
  24. EventQueue.invokeLater(new Runnable(){
  25. public void run() {
  26. Main ex = new Main();
  27. ex.setVisible(true);
  28. }
  29. });
  30. }
  31.  
  32. public class Canvas extends JComponent {
  33.  
  34. public void paint(Graphics g) {
  35. Graphics2D g2d = (Graphics2D) g;
  36. g2d.setColor(Color.decode("#3498db"));
  37. g2d.fillRect(100, 100, 200, 200);
  38.  
  39. g2d.dispose();
  40. //---------------------------------------------------------------------------------------------------
  41. }//end of paint(Graphics g)
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement