Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package zad4;
  2.  
  3. import static javax.swing.JOptionPane.showInputDialog;
  4.  
  5. import java.awt.Color;
  6. import java.awt.Graphics;
  7.  
  8. import javax.swing.*;
  9. public class jablka2 extends JFrame {
  10.  
  11.     private static int APPLES = 1;
  12.  
  13.     public static void main(String[] a) {
  14.         int proby = 3;
  15.         while(proby>0) {
  16.             String applesString = showInputDialog( "Podaj liczbe jablek:" );
  17.             try {
  18.                 APPLES = Integer.parseInt(applesString);
  19.             } catch (NumberFormatException e) {
  20.                 proby -= 1;
  21.                 javax.swing.JOptionPane.showMessageDialog(null, "To co podajesz powinno byc liczba calkowita.");
  22.                 continue;
  23.             }
  24.             break;
  25.         }
  26.         int height = APPLES/45;
  27.         MyJFrame f = new MyJFrame();
  28.         f.setTitle("Drawing Graphics in Frames");
  29.         f.setSize(75+33*APPLES,150+30*height);
  30.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.         f.setVisible(true);
  32.     }
  33.  
  34.     static class MyJFrame extends JFrame {
  35.         public void paint(Graphics g) {
  36.             int height = APPLES/50;
  37.             int appmod = APPLES % 50;
  38.             int end_width;
  39.             for(int c = 0; c < height+1; c++) {
  40.                 if(APPLES - c*50 < 50) {
  41.                     end_width = APPLES-c*50;
  42.                 }
  43.                 else {
  44.                     end_width = 50;
  45.                 }
  46.                 for (int i = 0; i < end_width; i++) {
  47.                     g.setColor(Color.red);
  48.                     g.fillArc(50+i*30,50+c*30,50,50,0,360);
  49.                     g.setColor(Color.black);
  50.                     g.drawArc(50+i*30,50+c*30,50,50,0,360);
  51.                     g.setColor(Color.black);
  52.                     int[] xogon = {70+i*30,75+i*30,80+i*30};
  53.                     int[] yogon = {105+c*30,99+c*30,105+c*30};
  54.                     g.fillPolygon(xogon,yogon, 3);
  55.                     int[] xlistek = {75+i*30,83+i*30,80+i*30,74+i*30};
  56.                     int[] ylistek = {51+c*30,45+c*30,36+c*30,45+c*30};
  57.                     g.setColor(Color.green);
  58.                     g.fillPolygon(xlistek,ylistek,4);
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement