Advertisement
EL_PEL

Clicker Script (test)

Mar 7th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.61 KB | None | 0 0
  1. package com.zetcode;
  2.  
  3. import javax.swing.JPanel;
  4.  
  5. public class Board extends JPanel {
  6.  
  7.     public Board() {}
  8. }
  9. package com.zetcode;
  10.  
  11. import java.awt.EventQueue;
  12. import javax.swing.JFrame;
  13.  
  14.  
  15. public class Application extends JFrame {
  16.    
  17.     public Application() {
  18.  
  19.         initUI();
  20.     }
  21.  
  22.     private void initUI() {
  23.  
  24.         add(new Board());
  25.  
  26.         setSize(250, 200);
  27.  
  28.         setTitle("Application");
  29.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         setLocationRelativeTo(null);
  31.     }    
  32.    
  33.     public static void main(String[] args) {
  34.        
  35.         EventQueue.invokeLater(new Runnable() {
  36.             @Override
  37.             public void run() {
  38.                 Application ex = new Application();
  39.                 ex.setVisible(true);
  40.             }
  41.         });
  42.     }
  43. }
  44. add(new Board());
  45. setSize(250, 250);
  46. setDefaultCloseOperation(EXIT_ON_CLOSE);
  47. setLocationRelativeTo(null);
  48. public static void main(String[] args) {
  49.    
  50.     EventQueue.invokeLater(new Runnable() {
  51.         @Override
  52.         public void run() {
  53.             Application ex = new Application();
  54.             ex.setVisible(true);
  55.         }
  56.     });
  57. }
  58. package com.zetcode;
  59.  
  60. import java.awt.BasicStroke;
  61. import java.awt.Color;
  62. import java.awt.Dimension;
  63. import java.awt.Graphics;
  64. import java.awt.Graphics2D;
  65. import java.awt.RenderingHints;
  66. import java.awt.geom.AffineTransform;
  67. import java.awt.geom.Ellipse2D;
  68.  
  69. import javax.swing.JPanel;
  70.  
  71. public class Board extends JPanel {
  72.  
  73.     @Override
  74.     public void paintComponent(Graphics g) {
  75.         super.paintComponent(g);
  76.  
  77.         drawDonut(g);
  78.     }
  79.  
  80.     private void drawDonut(Graphics g) {
  81.  
  82.         Graphics2D g2d = (Graphics2D) g;
  83.  
  84.         RenderingHints rh
  85.                 = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
  86.                         RenderingHints.VALUE_ANTIALIAS_ON);
  87.  
  88.         rh.put(RenderingHints.KEY_RENDERING,
  89.                 RenderingHints.VALUE_RENDER_QUALITY);
  90.  
  91.         g2d.setRenderingHints(rh);
  92.  
  93.         Dimension size = getSize();
  94.         double w = size.getWidth();
  95.         double h = size.getHeight();
  96.  
  97.         Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
  98.         g2d.setStroke(new BasicStroke(1));
  99.         g2d.setColor(Color.gray);
  100.  
  101.         for (double deg = 0; deg < 360; deg += 5) {
  102.             AffineTransform at
  103.                     = AffineTransform.getTranslateInstance(w/2, h/2);
  104.             at.rotate(Math.toRadians(deg));
  105.             g2d.draw(at.createTransformedShape(e));
  106.         }
  107.     }
  108. }
  109. Graphics2D g2d = (Graphics2D) g;
  110. private void drawDonut(Graphics g) {
  111. ...
  112. }
  113. RenderingHints rh
  114.         = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
  115.                 RenderingHints.VALUE_ANTIALIAS_ON);
  116.  
  117. rh.put(RenderingHints.KEY_RENDERING,
  118.         RenderingHints.VALUE_RENDER_QUALITY);
  119.  
  120. g2d.setRenderingHints(rh);
  121. Dimension size = getSize();
  122. double w = size.getWidth();
  123. double h = size.getHeight();
  124. Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
  125. g2d.setStroke(new BasicStroke(1));
  126. g2d.setColor(Color.gray);
  127. for (double deg = 0; deg < 360; deg += 5) {
  128.     AffineTransform at
  129.             = AffineTransform.getTranslateInstance(w/2, h/2);
  130.     at.rotate(Math.toRadians(deg));
  131.     g2d.draw(at.createTransformedShape(e));
  132. }
  133. package com.zetcode;
  134.  
  135. import java.awt.EventQueue;
  136. import javax.swing.JFrame;
  137.  
  138.  
  139. public class DonutExample extends JFrame {
  140.    
  141.     public DonutExample() {
  142.  
  143.         initUI();
  144.     }
  145.  
  146.     private void initUI() {
  147.  
  148.         add(new Board());
  149.  
  150.         setSize(330, 330);
  151.  
  152.         setTitle("Donut");
  153.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  154.         setLocationRelativeTo(null);
  155.     }    
  156.    
  157.     public static void main(String[] args) {
  158.        
  159.         EventQueue.invokeLater(new Runnable() {
  160.             @Override
  161.             public void run() {
  162.                 DonutExample ex = new DonutExample();
  163.                 ex.setVisible(true);
  164.             }
  165.         });
  166.     }
  167. }
  168. package com.zetcode;
  169.  
  170. import java.awt.Dimension;
  171. import java.awt.Graphics;
  172. import java.awt.Image;
  173. import javax.swing.ImageIcon;
  174. import javax.swing.JPanel;
  175.  
  176. public class Board extends JPanel {
  177.  
  178.     private Image bardejov;
  179.  
  180.     public Board() {
  181.  
  182.         initBoard();
  183.     }
  184.    
  185.     private void initBoard() {
  186.        
  187.         loadImage();
  188.        
  189.         int w = bardejov.getWidth(this);
  190.         int h =  bardejov.getHeight(this);
  191.         setPreferredSize(new Dimension(w, h));        
  192.     }
  193.    
  194.     private void loadImage() {
  195.        
  196.         ImageIcon ii = new ImageIcon("bardejov.png");
  197.         bardejov = ii.getImage();        
  198.     }
  199.  
  200.     @Override
  201.     public void paintComponent(Graphics g) {
  202.  
  203.         g.drawImage(bardejov, 0, 0, null);
  204.     }
  205. }
  206. ImageIcon ii = new ImageIcon("bardejov.png");
  207. bardejov = ii.getImage();
  208. g.drawImage(bardejov, 0, 0, null);
  209. int w = bardejov.getWidth(this);
  210. int h =  bardejov.getHeight(this);
  211. setPreferredSize(new Dimension(w, h));
  212. package com.zetcode;
  213.  
  214. import java.awt.EventQueue;
  215. import javax.swing.JFrame;
  216.  
  217. public class ImageExample extends JFrame {
  218.  
  219.     public ImageExample() {
  220.  
  221.         initUI();
  222.     }
  223.  
  224.     private void initUI() {
  225.  
  226.         add(new Board());
  227.  
  228.         pack();
  229.  
  230.         setTitle("Bardejov");
  231.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  232.         setLocationRelativeTo(null);
  233.     }
  234.  
  235.     public static void main(String[] args) {
  236.  
  237.         EventQueue.invokeLater(new Runnable() {
  238.  
  239.             @Override
  240.             public void run() {
  241.                 ImageExample ex = new ImageExample();
  242.                 ex.setVisible(true);
  243.             }
  244.         });
  245.     }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement