代码拉取完成,页面将自动刷新
同步操作将从 华南农业大学-吴春胤/java2021spring 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package java2020spring;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Calculator extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private static final String COMMANDS = null;
private static final Icon[] COMMAND = null;
private static final String M = null;
public static void main(String[] args) {
Calculator calculator=new Calculator();
calculator.setVisible(true);
}
public Calculator() throws HeadlessException {
super("Caculator");
resultText.setAlignmentX(RIGHT_ALIGNMENT);
this.setTitle(Const.TITLE);
this.setSize(Const.FRAME_W,Const.FRAME_H);
this.setLayout(new BorderLayout());
this.setLocation(Const.FRAME_X,Const.FRAME_Y);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
resultText.setBounds(20,18,255,115);
resultText.setAlignmentX(RIGHT_ALIGNMENT);
resultText.setEditable(false);
History.setBounds(290,40,250,370);
History.setAlignmentX(LEFT_ALIGNMENT);
History.setEditable(false);
label.setBounds(400,15,100,20);
j1.setBounds(20,18,320,115);
j1.setLayout(new GridLayout());
j2.setBounds(380,40,250,380);
j2.setLayout(new GridLayout());
resultText.setLineWrap(true);
resultText.setWrapStyleWord(true);
History.setLineWrap(true);
History.setWrapStyleWord(true);
g1.setViewportView(resultText);
g1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
g2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
g2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
g2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
j1.add(g1);
j2.add(g2);
this.add(j1);
this.add(j2);
this.setLayout(null);
this.add(label);
int x=20,y=150;
for (int i=0;i<KEYS.length;i++)
{
keys[i]=new JButton();
keys[i].setText(KEYS[i]);
keys[i].setBounds(x,y,60,40);
if(x<250) {
x+=65;
}
else {
x=20;
y+=45;
}
this.add(keys[i]);
}
for (int i=0;i<KEYS.length;i++)
{
keys[i].addActionListener(this);
}
this.setResizable(false);
this.setBounds(500,200,670,480);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
public void init() {
resultText.setBackground(Color.WHITE);
JPanel calckeysPanel=new JPanel();
resultText.setBackground(Color.WHITE);
calckeysPanel.setLayout(new GridLayout(5,5,3,3));
for(int i=0;i<keys.length;i++) {
keys[i]=new JButton(KEYS[i]);
calckeysPanel.add(keys[i]);
keys[i].setForeground(Color.BLACK);
keys[i].addActionListener(this);
this.setBackground(Color.LIGHT_GRAY);
this.pack();
}
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
private String[] KEYS= {"7","8","9","+","sqrt","4","5","6","-","%","1","2","3",
"*","1/x","+/-","0","=","/",".","(",")","e","x*x","Bac","C","MC",
"MR","MS","M+"};
private JButton keys[]=new JButton[KEYS.length];
private JTextArea resultText=new JTextArea("0");
private JTextArea History=new JTextArea();
private JPanel j1=new JPanel();
private JPanel j2=new JPanel();
private JScrollPane g1=new JScrollPane(resultText);
private JScrollPane g2=new JScrollPane(History);
private JLabel label=new JLabel("历史记录");
private String a="";
private JButton[] commands2;
private Array[] ms;
private JButton[] ms2;
public void actionPerformed(ActionEvent e) {
String label=e.getActionCommand();
if(label=="=")
{
resultText.setText(this.a);
History.setText(History.getText()+resultText.getText());
if(label=="=")
{
String s[]=houzhui(this.a);
String result=Result(s);
this.a=result+"";
resultText.setText(this.a);
History.setText(History.getText()+"="+resultText.getText()+"\n");
}
}
else if(label=="AC")
{
this.a="";
resultText.setText("0");
}
else if(label=="sqrt")
{
String n=k(this.a);
resultText.setText("sqqrt"+"("+this.a+")"+"="+n);
History.setText(History.getText()+"sqrt"+"("+this.a+")"+"=");
this.a=n;
}
else if(label=="x*x")
{
String m=p(this.a);
resultText.setText(this.a+"^2"+"="+m);
History.setText(History.getText()+this.a+"^2"+"=");
this.a=m;
}
else if(label=="e"||label=="pi")
{
if(label=="e")
{
String m=String.valueOf(2.7182818);
this.a=this.a+m;
resultText.setText(this.a);
}
if(label=="pi")
{
String m=String.valueOf(3.1415926);
this.a=this.a+m;
resultText.setText(this.a);
}
}
else
{
this.a=this.a+label;
resultText.setText(this.a);
}
}
private String p(String a2) {
// TODO 自动生成的方法存根
return null;
}
private String k(String a2) {
// TODO 自动生成的方法存根
return null;
}
private String Result(String[] s) {
// TODO 自动生成的方法存根
return null;
}
private String[] houzhui(String a2) {
// TODO 自动生成的方法存根
return null;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。