so i'm trying to make it where if these two shapes touch each other the window closes. Here is the first part
public class Mayflower {
JFrame f = new JFrame();
public static void main(String[] args) {
Mayflower bob = new Mayflower();
bob.Start();
}
private void Start(int clothes, int food, int repair, int money) {
int complete = 0;
Mayflower bob = new Mayflower();
//JOptionPane.showMessageDialog(null, "Your equipment:\nClothes - " + clothes + "\nFood - " + food + "\nrepair equipment - " + repair + "\nMoney left - $" + money);
bob.epic(complete);
}
public void epic(int complete) {
if (complete == 0){
Iceberg Tim = new Iceberg();
f.add(Tim);
f.setVisible(true);
f.setSize(600, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("SAILIN BABEEEEY");
f.setLocation(600, 200);
}
if(complete == 1){
System.out.println("odeyladoeijoo");
f.dispose();
}
}
}
Then it calls to the constructor iceberg where the minigame is, I deleted all the movement input because it wasn't relevant:
package mayflower;
public class Iceberg extends JPanel implements ActionListener, KeyListener {
Timer time = new Timer(5, this);
int x = 260;
int y = 500;
int velx = 0;
int vely = 0;
int hitscany = -4000;
int hitscanvely = -1;
public Iceberg() {
time.start();
addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g.setColor(MyColor1);
g.fillRect(x, y, 40, 60);
g.setColor(Color.GRAY);
g.fillRect(0, hitscany, 650, 0);
if (y == hitscany) {
int complete = 1;
Mayflower bob = new Mayflower();
bob.epic(complete);
}
time.start();
}
So i made it to where The "hitscan" object moves down the screen and when it touches the object the window is supposed to close. When my if statement (for if the y coordinates of the two objects are equal) calls the public void epic its supposed to "activate" the if statement for if complete is == 1 and dispose of the frame but for some reason it doesn't