Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad4;
- import static javax.swing.JOptionPane.showInputDialog;
- import java.awt.Color;
- import java.awt.Graphics;
- import javax.swing.*;
- public class jablka2 extends JFrame {
- private static int APPLES = 1;
- public static void main(String[] a) {
- int proby = 3;
- while(proby>0) {
- String applesString = showInputDialog( "Podaj liczbe jablek:" );
- try {
- APPLES = Integer.parseInt(applesString);
- } catch (NumberFormatException e) {
- proby -= 1;
- javax.swing.JOptionPane.showMessageDialog(null, "To co podajesz powinno byc liczba calkowita.");
- continue;
- }
- break;
- }
- int height = APPLES/45;
- MyJFrame f = new MyJFrame();
- f.setTitle("Drawing Graphics in Frames");
- f.setSize(75+33*APPLES,150+30*height);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setVisible(true);
- }
- static class MyJFrame extends JFrame {
- public void paint(Graphics g) {
- int height = APPLES/50;
- int appmod = APPLES % 50;
- int end_width;
- for(int c = 0; c < height+1; c++) {
- if(APPLES - c*50 < 50) {
- end_width = APPLES-c*50;
- }
- else {
- end_width = 50;
- }
- for (int i = 0; i < end_width; i++) {
- g.setColor(Color.red);
- g.fillArc(50+i*30,50+c*30,50,50,0,360);
- g.setColor(Color.black);
- g.drawArc(50+i*30,50+c*30,50,50,0,360);
- g.setColor(Color.black);
- int[] xogon = {70+i*30,75+i*30,80+i*30};
- int[] yogon = {105+c*30,99+c*30,105+c*30};
- g.fillPolygon(xogon,yogon, 3);
- int[] xlistek = {75+i*30,83+i*30,80+i*30,74+i*30};
- int[] ylistek = {51+c*30,45+c*30,36+c*30,45+c*30};
- g.setColor(Color.green);
- g.fillPolygon(xlistek,ylistek,4);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement