Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)Wall.java
- *
- * Wall Applet application
- *
- * @author Joseph Kraemer
- * @CSci 1130-01/51/91
- * @version 1.00 2014/7/17
- */
- import java.awt.*;
- import javax.swing.*;
- import java.applet.*;
- import java.util.*;
- import java.awt.event.*;
- public class Wall extends JApplet implements ActionListener
- {
- JTextField enter;
- Boolean submit;
- JLabel bricks;
- JButton build;
- JPanel top;
- Image zombie;
- int value;
- public void init()
- {
- setLayout(new BorderLayout());
- top = new JPanel();
- build = new JButton ("AHHHHHH...ZOMBIES!"); //button for building wall
- bricks = new JLabel("Enter between 1 & 20 rows to contruct:");
- enter = new JTextField(2);
- top.add(build); //add zombie button
- top.add(bricks); //add intructions
- top.add(enter); //add text field
- add(top,BorderLayout.NORTH);
- build.addActionListener(this);
- }
- public void actionPerformed(ActionEvent ae)
- {
- if (ae.getSource()==build)
- {
- int value = Integer.parseInt(build.getText());
- if (value>0 && value <21)
- {
- submit = true;
- repaint();
- }
- else
- {
- submit = false;
- repaint();
- }
- }
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- //add zombie image
- Image zombie = getImage(getCodeBase(),"Zombie.jpg");
- g.drawImage(zombie, 0, 45, this);
- if (submit = false) //add error message
- {
- g.setColor(Color.WHITE);
- g.setFont( new Font( "TimesRoman", Font.BOLD, 40 ));
- g.drawString("You must enter a number between 1 & 20!", 400, 100); //add message
- }
- int brick_width = 50;
- int brick_height = 20;
- int spacing = 1;
- int x = 0;
- while(<21)
- {
- drawBrick(g, nextInt(brick_width+spacing), nextInt(brick_height+spacing));
- x=x-25+getWidth()+50;
- x++;
- }
- }
- public void drawBrick(Graphics g, int x, int y)
- {
- g.setColor(new Color(150, 0, 0));
- g.fillRect(0, 635, 50, 20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement