I have two java classes. One is a JFrame that displays the methods from the applet. I want the TollboothDisplay java to change whenever the Booth applet is ran. Here are both of the programs. TollboothDisplay.java
package Booth;
/**
* Write a description of class TollboothDisplay here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class TollboothDisplay extends JFrame
{
private JLabel count;
private JLabel money;
private Booth myBooth;
/**
* Constructor for objects of class TollboothDisplay
*/
public TollboothDisplay()
{
myBooth = new Booth();
count = new JLabel("Number of Cars: " + myBooth.traffic());
money = new JLabel("Amount Collected: $" + myBooth.profit());
getContentPane().add(count,BorderLayout.NORTH);
getContentPane().add(money,BorderLayout.SOUTH);
addMouseListener(new click());
myBooth.add(myBooth);
}
public void update()
{
count.setText("Number of Cars: " + myBooth.traffic());
money.setText("Amount Collected: $" + myBooth.profit());
repaint();
}
public void paint(Graphics g)
{
paintComponents(g);
}
@SuppressWarnings("deprecation")
public static void main(String args[])
{
TollboothDisplay myDisplay = new TollboothDisplay();
myDisplay.setSize(200,200);
myDisplay.show();
myDisplay.setTitle("Tollbooth Version 1");
}
private class click implements MouseListener
{
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){
myBooth.addCar();
update();}
}
}
Booth.java
package Booth;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Class Booth - write a description of the class here
*
* @author (your name)
* @version (a version number)
*/
@SuppressWarnings({ "serial", "unused" })
public class Booth extends Applet implements ActionListener
{
//Panel panel;
Label label;
Button b;
int countCars;
public void init()
{
//panel= new Panel();
b=new Button("Add Car");
label = new Label();
//add(panel);
add(b);
add(label);
b.addActionListener(this);
countCars = 0;
}
public void actionPerformed(ActionEvent e)
{ countCars++;
label.setText(""+countCars);
validate();
invalidate();
}
public int traffic() {
return countCars;
}
public double profit() {
double price = countCars * 3.25;
return price;
}
public int addCar() {
return countCars;
}
}