Issue
so i created a simple calculator on netbeans, first i used the Jbutton for the numbers and operation symbols and it works fine you can click it and it will register on the textfield very fast. and then i changed the Jbutton and replaced it with a Jlabel because i dont like the look of the Jbutton and i dont want it to have a border. after i replaced all of it with a Jlabel, I tested it and it works but sometimes it wont register to the jtextfield, you need to click it again just to make it work. is it the code? or is it just my computer that has a problem.
private void zeroMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String enternumber = Display.getText() + zero.getText();
Display.setText(enternumber);
}
private void nineMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String enternumber = Display.getText() + nine.getText();
Display.setText(enternumber);
}
private void eightMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String enternumber = Display.getText() + eight.getText();
Display.setText(enternumber);
}
SOLVED : I tried using MousePressed Instead of MouseClicked
Solution
First of all, in github add gitignore
file, noone really cares about your .class
files which are made after every compilation of different code.
Secondly use import, example import javax.swing.*;
or import organization if you wish to list all specific libraries. In eclipse e.g. ctr+shift+O
does the job.
And answering your question try using mouse pressed instead of mouse clicked. It seems that there is no difference but I read a lot about it and seems that pressed is less likely failover ;) And in the future try posting some code, perfectly short, relevant to question. Trust me, one day you will find your old projects funny then You will decide to delete your github repo and in result this question wouldn't be useful anymore even if my answer might be right.
Answered By - kolboc
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)