Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- enter.addActionListener(this);
- }
- public void actionPerformed(ActionEvent ae)
- {
- if (ae.getSource()==enter)
- {
- int value = Integer.parseInt(enter.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.RED);
- g.setFont( new Font( "TimesRoman", Font.BOLD, 30 ));
- g.drawString("You must enter a number between 1 & 20!", 200, 100); //add message
- }
- int brick_width = 50;
- int brick_height = 20;
- int spacing = 1;
- int x = 0;
- while(x<21)
- {
- // drawBrick(g, nextInt(brick_width+spacing), nextInt(brick_height+spacing));
- // x=x+getWidth()+50;
- // 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