Basically, I'm trying to make it so every time you click somewhere in the JFrame, the JLabel gets added by 1. The problem is, if I were to print out the value of amount, it increases, but the actual JLabel continues to stay the same.
To try and fix this I tried to update the JLabel object every time you click but that didn't seem to work either. (Did this by writing "JLabel();") Other than that, I really can't think of what it might be,
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Franels extends MouseAdapter {
int width, height;
int amount = 0;
JFrame frame = new JFrame("Title");
JPanel panel = new JPanel();
JButton button = new JButton("Hello");
JLabel label = new JLabel();
public void FrameConfig(int width, int height) {
this.width = width;
this.height = height;
frame.setSize(width, height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLayout(null);
frame.setResizable(false);
frame.add(panel);
frame.getContentPane().addMouseListener(new Franels());
}
public void PanelConfig() {
panel.setBounds(300, 300, 300, 300);
panel.setBackground(Color.blue);
panel.setVisible(true);
panel.add(label);
}
public void LabelConfig() {
label.setForeground(Color.red);
label.setText(String.valueOf(amount));
}
public void mouseClicked(MouseEvent e) {
amount++;
LabelConfig();
System.out.println(amount);
}
}
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String args[]) {
Franels windows = new Franels();
windows.FrameConfig(900, 900);
windows.PanelConfig();
windows.LabelConfig();
}
}