Advertisement
Guest User

wall

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