1 Star 0 Fork 0

赏镜猎人/swing-calc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AnswerLabel.java 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
赏镜猎人 提交于 2021-07-02 02:00 . Init.
import javax.swing.*;
import java.awt.*;
public class AnswerLabel extends JLabel {
boolean abort, point_used;
public static final int SAFE = 0, EXPLICT = 1, ABORT = 2;
int status;
void abort() {
setStatus(ABORT);
}
void setStatus(int s) {
status = s;
}
int getStatus() {return status;}
void reset() {
setStatus(ABORT);
point_used = false;
}
void loadDouble(double d) {
//System.out.println("loadDouble(" + d + ")");
this.setText(d + "");
String s = this.getText();
if(s.charAt(s.length() - 1) == '0' && s.charAt(s.length() - 2) == '.') this.setText(s.substring(0, s.length() - 2));
}
void append(char c) {
//System.out.println("append(" + c + ")");
if(getStatus() != SAFE) {
setStatus(SAFE);
this.setText("0");
}
/*
if(c == '.' && point_used == true) return;
if(this.getText() != "0") this.setText(this.getText() + c);
else this.setText("" + c);
if(c == '.') point_used = true;
*/
if(c == '.') {
if(point_used == true) return;
point_used = true;
this.setText(this.getText() + c);
return;
}
if(this.getText() != "0") this.setText(this.getText() + c);
else this.setText("" + c);
}
void backspace() {
if(getStatus() != SAFE) {
setStatus(SAFE);
this.setText("0");
}else{
String s = getText();
char c = s.charAt(s.length() - 1);
if(c == '.') point_used = false;
setText(s.substring(0, s.length() - 1));
}
}
public AnswerLabel()
{
reset();
this.setText("0");
this.setFont(new Font("MS Yahei", Font.PLAIN, 20));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/bouncy-hunter/swing-calc.git
[email protected]:bouncy-hunter/swing-calc.git
bouncy-hunter
swing-calc
swing-calc
master

搜索帮助