import javax.swing.JApplet;
import java.awt.Graphics;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.AbstractButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
public class superclass extends JApplet
{
private Image iron;
private Image hulk;
private Image thor;
private Image cap;
private Image exp;
private int Car1, Car2, Car3, Car4;
private JTextField one;
private JTextField two;
private JTextField three;
private JTextField four;
private JPanel big;
private JButton click, unclick;
private Timer timer1;
private int a, b, c, d;
private JLabel onelabel;
private JLabel twolabel;
private JLabel threelabel;
private JLabel fourlabel;
public void init()
{
JPanel big = new JPanel();
int APPLET_WIDTH = 500;
int APPLET_HEIGHT = 500;
big.setPreferredSize(new Dimension(APPLET_WIDTH,APPLET_HEIGHT));
big.setOpaque(true);
Container background = getContentPane();
background.setBackground(Color.blue);
setLayout(new FlowLayout());
JTextField finalone = new JTextField("", 3);
JTextField finaltwo = new JTextField("", 3);
JTextField finalthree = new JTextField("", 3);
JTextField finalfour = new JTextField("", 3);
JLabel onelabel = new JLabel("IronMan:");
JLabel twolabel = new JLabel("Thor:");
JLabel threelabel = new JLabel("Hulk:");
JLabel fourlabel = new JLabel("Captain America:");
click = new JButton("Avengers, MOVE OUT!!");
click.setActionCommand("enable");
unclick = new JButton("Avengers, Halt!");
timer1 = new Timer(0, new TimerHandler());
big.add(onelabel);
big.add(one);
big.add(twolabel);
big.add(two);
big.add(threelabel);
big.add(three);
big.add(fourlabel);
big.add(four);
big.add(click);
big.add(unclick);
iron = getImage(getDocumentBase(),"ironman.jpg");
hulk = getImage(getDocumentBase(), "hulk.jpg");
thor = getImage(getDocumentBase(), "thor.jpg");
cap = getImage(getDocumentBase(), "america.jpg");
exp = getImage(getDocumentBase(), "explosion.jpg");
add(big);
JOptionPane.showMessageDialog(null, "AVENGERS MOVE OUT!! \n" + "To make your SuperHeros accelerate move please enter a\n" +
"number between 1 and 40 in each text box. \n" + "\n" +
"1 = Slowest Speed 40 = Fastest Speed\n" + "\n" +
"If you enter a number lower than 1,\n" +
"your Speed will round up to 1.\n" + "\n" +
"If your number entered is higher than 40,\n" +
"The Speed will be converted to 40. ");
a = 0;
b = 0;
c = 0;
d = 0;
}
public void start(){
click.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
Car1 = Integer.parseInt(one.getText());
Car2 = Integer.parseInt(two.getText());
Car3 = Integer.parseInt(three.getText());
Car4 = Integer.parseInt(four.getText());
if(Car1 > 40)
{
Car1 = 40;
}
else if(Car1 < 1)
{
Car1 = 1;
}
if(Car2 > 40)
{
Car2 = 40;
}
else if(Car2 < 1)
{
Car2 = 1;
}
if(Car3 > 40)
{
Car3 = 40;
}
else if(Car3 < 1)
{
Car3 = 1;
}
if(Car4 > 40)
{
Car4 = 40;
}
else if(Car4 < 1)
{
Car4 = 1;
}
timer1.start();
}
});
unclick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent b)
{
Car1 = 0;
Car2 = 0;
Car3 = 0;
Car4 = 0;
timer1.stop();
}
});
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.BLACK);
g.drawLine(0, 100, 500, 100);
g.drawLine(0, 200, 500, 200);
g.drawLine(0, 300, 500, 300);
g.drawLine(0, 400, 500, 400);
g.drawLine(0, 500, 500, 500);
g.drawImage(iron, Car1, 100 ,100, 100, this);
g.drawImage(exp, 100, 100, 500, 500, this);
g.drawImage(hulk, Car2, 200, 100, 100, this);
g.drawImage(thor, Car3, 300, 100,100, this);
g.drawImage(cap, Car4, 400, 100,100, this);
}
private class TimerHandler implements ActionListener
{
public void actionPerformed(ActionEvent actionEvent)
{
repaint();
Car1++;
Car2++;
Car3++;
Car4++;
}
}
}