⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonpanel.java

📁 做了一个还算复杂的计算器,还是有一定的 参考价值的(比较适合中初级者)
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    			    inter = inter+"A";	
    	    }
    		jtaExpPanel.setText(memory);
    	}
    	if (e.getSource()==jbtData[11]&&jrbHex.isSelected()){
    		memory=memory+"B";
    		if (count==0)
    			inter=inter+"B";
    		else{
    			if (innerExpression[count-1]!="."&&innerExpression[count-1]!="1"&&innerExpression[count-1]!="2"&&innerExpression[count-1]!="3"
    			    &&innerExpression[count-1]!="4"&&innerExpression[count-1]!="5"&&innerExpression[count-1]!="6"&&innerExpression[count-1]!="7"
    			    &&innerExpression[count-1]!="8"&&innerExpression[count-1]!="9"&&innerExpression[count-1]!="0")
    			    inter = inter+"B";	
    	    }
    		jtaExpPanel.setText(memory);
    	}
    	if (e.getSource()==jbtData[12]&&jrbHex.isSelected()){
    		memory=memory+"C";
    		if (count==0)
    			inter=inter+"C";
    		else{
    			if (innerExpression[count-1]!="."&&innerExpression[count-1]!="1"&&innerExpression[count-1]!="2"&&innerExpression[count-1]!="3"
    			    &&innerExpression[count-1]!="4"&&innerExpression[count-1]!="5"&&innerExpression[count-1]!="6"&&innerExpression[count-1]!="7"
    			    &&innerExpression[count-1]!="8"&&innerExpression[count-1]!="9"&&innerExpression[count-1]!="0")
    			    inter = inter+"C";	
    	    }
    		jtaExpPanel.setText(memory);
    		
    	}
    	if (e.getSource()==jbtData[13]&&jrbHex.isSelected()){
    		memory=memory+"D";
    		if (count==0)
    			inter=inter+"D";
    		else{
    			if (innerExpression[count-1]!="."&&innerExpression[count-1]!="1"&&innerExpression[count-1]!="2"&&innerExpression[count-1]!="3"
    			    &&innerExpression[count-1]!="4"&&innerExpression[count-1]!="5"&&innerExpression[count-1]!="6"&&innerExpression[count-1]!="7"
    			    &&innerExpression[count-1]!="8"&&innerExpression[count-1]!="9"&&innerExpression[count-1]!="0")
    			    inter = inter+"D";	
    	    }
    		jtaExpPanel.setText(memory);
    	}
    	if (e.getSource()==jbtData[14]&&jrbHex.isSelected()){
    		memory=memory+"E";
    		if (count==0)
    			inter=inter+"E";
    		else{
    			if (innerExpression[count-1]!="."&&innerExpression[count-1]!="1"&&innerExpression[count-1]!="2"&&innerExpression[count-1]!="3"
    			    &&innerExpression[count-1]!="4"&&innerExpression[count-1]!="5"&&innerExpression[count-1]!="6"&&innerExpression[count-1]!="7"
    			    &&innerExpression[count-1]!="8"&&innerExpression[count-1]!="9"&&innerExpression[count-1]!="0")
    			    inter = inter+"E";	
    	    }
    		jtaExpPanel.setText(memory);
    	}
    	if (e.getSource()==jbtData[15]&&jrbHex.isSelected()){
    		memory=memory+"F";
    		if (count==0)
    			inter=inter+"F";
    		else{
    			if (innerExpression[count-1]!="."&&innerExpression[count-1]!="1"&&innerExpression[count-1]!="2"&&innerExpression[count-1]!="3"
    			    &&innerExpression[count-1]!="4"&&innerExpression[count-1]!="5"&&innerExpression[count-1]!="6"&&innerExpression[count-1]!="7"
    			    &&innerExpression[count-1]!="8"&&innerExpression[count-1]!="9"&&innerExpression[count-1]!="0")
    			    inter = inter+"F";	
    	    }
    		jtaExpPanel.setText(memory);
    	}
    	if (e.getSource()==jrbBinary){
    		if (inter!=""){
    		    if (selection==JRB_BINARY)
    		    	inter = new DataStringDeal().BinaryToDecimalString(inter);
    		    if (selection==JRB_OCTAL)
    		    	inter = new DataStringDeal().OctalToDecimalString(inter);
    		    if (selection==JRB_HEX)
    		    	inter = new DataStringDeal().HexToDecimalString(inter); 
    			innerExpression[count]=inter;
    			count++;
    			if (count>=innerExpression.length){
    			    String[] temp = new String[count*2];
    			    for (int i=0;i<innerExpression.length;i++)
    				    temp[i]=innerExpression[i];
    			    innerExpression=temp;
    		    }
    			inter="";
    		}
    		if (selection==JRB_OCTAL){
    		    memory = new DataStringDeal().DecimalToBinaryString(new DataStringDeal().OctalToDecimalString(memory));
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_BINARY;
    		}
    		if (selection==JRB_DECIMAL){
    		    memory = new DataStringDeal().DecimalToBinaryString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_BINARY;
    		}
    		if (selection==JRB_HEX){
    			memory = new DataStringDeal().DecimalToBinaryString(new DataStringDeal().HexToDecimalString(memory));
    			jtaExpPanel.setText(memory);
    			selection = JRB_BINARY;
    		}	
    		jtaMemory.setText("当前为二进制状态,亮色按钮为支持设备");
    		for (int i=2;i<=15;i++)
    			jbtData[i].setBackground(Color.LIGHT_GRAY);
    		jbtSin.setBackground(Color.LIGHT_GRAY);
    		jbtCos.setBackground(Color.LIGHT_GRAY);
    		jbtLn.setBackground(Color.LIGHT_GRAY);
    		jbtSqrt.setBackground(Color.LIGHT_GRAY);
    		jbtSqr.setBackground(Color.LIGHT_GRAY);
    		jbtPow.setBackground(Color.LIGHT_GRAY);
    		jbtLog.setBackground(Color.LIGHT_GRAY);
    		jbtFac.setBackground(Color.LIGHT_GRAY);
    	}
    	if (e.getSource()==jrbOctal){
    		if (inter!=""){
    		    if (selection==JRB_BINARY)
    		    	inter = new DataStringDeal().BinaryToDecimalString(inter);
    		    if (selection==JRB_OCTAL)
    		    	inter = new DataStringDeal().OctalToDecimalString(inter);
    		    if (selection==JRB_HEX)
    		    	inter = new DataStringDeal().HexToDecimalString(inter); 
    			innerExpression[count]=inter;
    			count++;
    			if (count>=innerExpression.length){
    			    String[] temp = new String[count*2];
    			    for (int i=0;i<innerExpression.length;i++)
    				    temp[i]=innerExpression[i];
    			    innerExpression=temp;
    		    }
    			inter="";
    		}
    		jtaMemory.setText("当前为八进制状态,亮色按钮为支持设备");
    		if (selection==JRB_BINARY){
    		    memory = new DataStringDeal().DecimalToOctalString(new DataStringDeal().BinaryToDecimalString(memory));
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_OCTAL;
    		}
    		if (selection==JRB_DECIMAL){
    		    memory = new DataStringDeal().DecimalToOctalString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_OCTAL;
    		}
    		if (selection==JRB_HEX){
    		    memory = new DataStringDeal().DecimalToOctalString(new DataStringDeal().HexToDecimalString(memory));
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_OCTAL;
    		}
    		for (int i=2;i<8;i++)
    			jbtData[i].setBackground(jbtStart.getBackground());
    		for (int i=8;i<=15;i++)
    			jbtData[i].setBackground(Color.LIGHT_GRAY);
    		jbtSin.setBackground(Color.LIGHT_GRAY);
    		jbtCos.setBackground(Color.LIGHT_GRAY);
    		jbtLn.setBackground(Color.LIGHT_GRAY);
    		jbtSqrt.setBackground(Color.LIGHT_GRAY);
    		jbtSqr.setBackground(Color.LIGHT_GRAY);
    		jbtPow.setBackground(Color.LIGHT_GRAY);
    		jbtLog.setBackground(Color.LIGHT_GRAY);
    		jbtFac.setBackground(Color.LIGHT_GRAY);
    	}
    	if (e.getSource()==jrbDecimal){
    		if (inter!=""){
    		    if (selection==JRB_BINARY)
    		    	inter = new DataStringDeal().BinaryToDecimalString(inter);
    		    if (selection==JRB_OCTAL)
    		    	inter = new DataStringDeal().OctalToDecimalString(inter);
    		    if (selection==JRB_HEX)
    		    	inter = new DataStringDeal().HexToDecimalString(inter); 
    			innerExpression[count]=inter;
    			count++;
    			if (count>=innerExpression.length){
    			    String[] temp = new String[count*2];
    			    for (int i=0;i<innerExpression.length;i++)
    				    temp[i]=innerExpression[i];
    			    innerExpression=temp;
    		    }
    			inter="";
    		}
    		jtaMemory.setText("当前为十进制状态,亮色按钮为支持设备");
    		if (selection==JRB_BINARY){
    		    memory = new DataStringDeal().BinaryToDecimalString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_DECIMAL;
    		}
    		if (selection==JRB_OCTAL){
    		    memory = new DataStringDeal().OctalToDecimalString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_DECIMAL;
    		}
    		if (selection==JRB_HEX){
    		    memory = new DataStringDeal().HexToDecimalString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_DECIMAL;
    		}
    		for (int i=2;i<10;i++)
    			jbtData[i].setBackground(jbtStart.getBackground());
    		for (int i=10;i<=15;i++)
    			jbtData[i].setBackground(Color.LIGHT_GRAY);
    		jbtSin.setBackground(jbtStart.getBackground());
    		jbtCos.setBackground(jbtStart.getBackground());
    		jbtLn.setBackground(jbtStart.getBackground());
    		jbtSqrt.setBackground(jbtStart.getBackground());
    		jbtSqr.setBackground(jbtStart.getBackground());
    		jbtPow.setBackground(jbtStart.getBackground());
    		jbtLog.setBackground(jbtStart.getBackground());
    		jbtFac.setBackground(jbtStart.getBackground());
    	}
    	if (e.getSource()==jrbHex){
    		if (inter!=""){
    		    if (selection==JRB_BINARY)
    		    	inter = new DataStringDeal().BinaryToDecimalString(inter);
    		    if (selection==JRB_OCTAL)
    		    	inter = new DataStringDeal().OctalToDecimalString(inter);
    		    if (selection==JRB_HEX)
    		    	inter = new DataStringDeal().HexToDecimalString(inter); 
    			innerExpression[count]=inter;
    			count++;
    			if (count>=innerExpression.length){
    			    String[] temp = new String[count*2];
    			    for (int i=0;i<innerExpression.length;i++)
    				    temp[i]=innerExpression[i];
    			    innerExpression=temp;
    		    }
    			inter="";
    		}
    		if (selection==JRB_BINARY){
    		    memory = new DataStringDeal().DecimalToHexString(new DataStringDeal().BinaryToDecimalString(memory));
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_HEX;
    		}
    		if (selection==JRB_OCTAL){
    		    memory = new DataStringDeal().DecimalToHexString(new DataStringDeal().OctalToDecimalString(memory));
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_HEX;
    		}
    		if (selection==JRB_DECIMAL){
    		    memory = new DataStringDeal().DecimalToHexString(memory);
    		    jtaExpPanel.setText(memory);
    		    selection = JRB_HEX;
    		}
    		jtaMemory.setText("当前为十六进制状态,亮色按钮为支持设备");
    		for (int i=2;i<16;i++)
    			jbtData[i].setBackground(jbtStart.getBackground());
    		jbtSin.setBackground(Color.LIGHT_GRAY);
    		jbtCos.setBackground(Color.LIGHT_GRAY);
    		jbtLn.setBackground(Color.LIGHT_GRAY);
    		jbtSqrt.setBackground(Color.LIGHT_GRAY);
    		jbtSqr.setBackground(Color.LIGHT_GRAY);
    		jbtPow.setBackground(Color.LIGHT_GRAY);
    		jbtLog.setBackground(Color.LIGHT_GRAY);
    		jbtFac.setBackground(Color.LIGHT_GRAY);
    	}
    	if (e.getSource()==jbtHelp){
    		jtaMemory.setText("1.所有存在二义性的表达式本计算器均不支持\n"+
    			                "例如2^2^2存在二义性,规定为不合法的\n"+
    			                "有二义性的表达式必须要加括号!\n"+
    			              "2.LOG的用法:2LOG3代表平时所描述的拼音logeersan\n"+
    			                "例如LNcoscoscos2是支持的"+		
    			              "3.详细说明见说明文档");
    	}
    	if (e.getSource()==jbtStorage){
    		if (count>0){
    			storeCount = count;
    			storeMemory = memory;
    			storeInnerExpression = (String[])(innerExpression.clone());
    			storeInter = inter;
    			jtaMemory.setText("存储成功!");
    		}
    	}
    	if (e.getSource()==jbtRead){
    		if (storeCount>0){
    			count = storeCount;
    			memory = storeMemory;
    			innerExpression = (String[])(storeInnerExpression.clone());
    			for (int i=0;i<innerExpression.length;i++)
    				System.out.print(innerExpression[i]);
    			inter = storeInter;
    			jtaExpPanel.setText(memory);
    			jtaMemory.setText("读取成功!");
    		}
    	}
    }
    
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -