Advertisement
Guest User

wall

a guest
Jul 24th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. /**
  2.  * @(#)Wall.java
  3.  *
  4.  * Wall Applet application
  5.  *
  6.  * @author Joseph Kraemer
  7.  * @CSci 1130-01/51/91
  8.  * @version 1.00 2014/7/17
  9.  */
  10.  
  11. import java.awt.*;
  12. import javax.swing.*;
  13. import java.applet.*;
  14. import java.util.*;
  15. import java.awt.event.*;
  16.  
  17. public class Wall extends JApplet implements ActionListener
  18. {
  19.    
  20.     JTextField enter;
  21.     Boolean submit;
  22.     JLabel bricks;
  23.     JButton build;
  24.     JPanel top;
  25.     Image zombie;
  26.     int value;
  27.    
  28.     public void init()
  29.     {
  30.         setLayout(new BorderLayout());
  31.        
  32.         top = new JPanel();
  33.         build = new JButton ("AHHHHHH...ZOMBIES!");                         //button for building wall
  34.         bricks = new JLabel("Enter between 1 & 20 rows to contruct:");     
  35.         enter = new JTextField(2);
  36.            
  37.         top.add(build);         //add zombie button
  38.         top.add(bricks);        //add intructions
  39.         top.add(enter);         //add text field
  40.         add(top,BorderLayout.NORTH);
  41.        
  42.        
  43.         build.addActionListener(this);
  44.        
  45.        
  46.     }
  47.     public void actionPerformed(ActionEvent ae)
  48.     {
  49.         if (ae.getSource()==build)
  50.         {
  51.             int value = Integer.parseInt(build.getText());
  52.             if (value>0 && value <21)
  53.             {
  54.                 submit = true;
  55.                 repaint();
  56.             }
  57.             else
  58.             {
  59.                 submit = false;
  60.                 repaint();
  61.             }  
  62.            
  63.         }  
  64.     }  
  65.  
  66.  
  67.     public void paint(Graphics g)
  68.     {
  69.         super.paint(g);
  70.    
  71.         //add zombie image
  72.         Image zombie = getImage(getCodeBase(),"Zombie.jpg");
  73.         g.drawImage(zombie, 0, 45, this);
  74.    
  75.         if (submit = false) //add error message
  76.         {
  77.             g.setColor(Color.WHITE);                       
  78.             g.setFont( new Font( "TimesRoman", Font.BOLD, 40 ));                   
  79.             g.drawString("You must enter a number between 1 & 20!", 400, 100);  //add message
  80.         }
  81.    
  82.         int brick_width = 50;
  83.         int brick_height = 20;
  84.         int spacing = 1;   
  85.         int x = 0;
  86.         while(x<21)
  87.         {
  88.             drawBrick(g, nextInt(brick_width+spacing), nextInt(brick_height+spacing));
  89.                 x=x+getWidth()+50;
  90.                 x=x-25+getWidth()+50;
  91.                 x++;   
  92.            
  93.         }  
  94.                
  95.     }
  96.    
  97.     public void drawBrick(Graphics g, int x, int y)
  98.     {
  99.         g.setColor(new Color(150, 0, 0));
  100.         g.fillRect(0, 635, 50, 20);
  101.     }  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement