資源簡介
java編寫的計算器,能實現加減乘除。
//***該夢幻計算器與Windows附件自帶計算器的標準版功能、界面相仿***//
//******但還不支持鍵盤操作,如有需要,下一次等級將滿足你**********//
import java.awt.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.Component.*;
import java.awt.color.*;
import java.text.DecimalFormat;
//*****************************************************************************//
//*****************************************************************************//
public class Calculator implements ActionListener //導入動作監聽接口
{
//******************************//
//*****設計計算器界面的單位*****//
JFrame frame; //定義框架
JTextField textAnswer; //定義輸出顯示框
JPanel panel, panel1, panel2, panel3;//定義面板作為子容器,從而達到要求的界面效果
JMenuBar mainMenu;
JTextField textMemory;
JLabel labelMemSpace; //labelMemSpace單純做擺設,控制面板的形狀
JButton buttonBk, buttonCe, buttonC;
JButton button[];
JButton buttonMC, buttonMR, buttonMS, buttonMAdd;
JButton buttonDot, buttonAddAndSub, buttonAdd, buttonSub, buttonMul,buttonDiv, buttonMod;
JButton buttonSqrt, buttonDao, buttonEqual;
JMenu editMenu, viewMenu, helpMenu;
JMenuItem copyItem, pasteItem, tItem, sItem, numberGroup, topHelp, aboutCal,myCollege;
DecimalFormat df; //設置數據輸出精度
boolean clickable; //控制當前能否按鍵
double memoryd; //使用內存中存儲的數字
int memoryi;
double vard, answerd; //用來保存double型數據的中間值(vard)和最后結果(answerd)
short key = -1, prekey = -1; //key用來保存當前進行何種運算,prekey用來保存前次進行何種運算
boolean clear = false;
String copy; //做復制用
JTextArea help; //幫助
JScrollPane scrollHelp;
static boolean One =true;
//******************//
//*****構造函數開始*****//
public Calculator()
{
clickable = true;
answerd = 0;
frame = new JFrame("夢幻計算器--SWE08008");
frame.setResizable(false);//不允許改變計算器的大小
frame.setLocation(250,150);//設置計算器的起始位置
frame.setBackground(Color.YELLOW);
df = new DecimalFormat("0.##############"); //設置數據輸出精度(對于double型值)
代碼片段和文件信息
//***該夢幻計算器與Windows附件自帶計算器的標準版功能、界面相仿***//
//******但還不支持鍵盤操作如有需要,下一次等級將滿足你**********//
import?java.awt.*;?
import?java.lang.*;
import?javax.swing.*;?
import?javax.swing.event.*;?
import?java.awt.event.*;?
import?java.awt.Component.*;
import?java.awt.color.*;
import?java.text.DecimalFormat;?
//*****************************************************************************//
//*****************************************************************************//
public?class?Calculator?implements?ActionListener?//導入動作監聽接口?
{
//******************************//
?? //*****設計計算器界面的單位*****//
Jframe?frame;?//定義框架
?? JTextField?textAnswer;?//定義輸出顯示框
?? JPanel?panel?panel1?panel2?panel3;//定義面板作為子容器,從而達到要求的界面效果?
?? JMenuBar?mainMenu;?
?? JTextField?textMemory;?
?? JLabel?labelMemSpace;?//labelMemSpace單純做擺設,控制面板的形狀?
?? JButton?buttonBk?buttonCe?buttonC;?
?? JButton?button[];?
?? JButton?buttonMC?buttonMR?buttonMS?buttonMAdd;?
?? JButton?buttonDot?buttonAddAndSub?buttonAdd?buttonSub?buttonMulbuttonDiv?buttonMod;?
?? JButton?buttonSqrt?buttonDao?buttonEqual;?
?? JMenu?editMenu?viewMenu?helpMenu;?
?? JMenuItem?copyItem?pasteItem?tItem?sItem?numberGroup?topHelp?aboutCalmyCollege;?
?? DecimalFormat?df;?//設置數據輸出精度?
?? boolean?clickable;?//控制當前能否按鍵?
?? double?memoryd;?//使用內存中存儲的數字?
?? int?memoryi;?
?? double?vard?answerd;?//用來保存double型數據的中間值(vard)和最后結果(answerd)?
?? short?key?=?-1?prekey?=?-1;?//key用來保存當前進行何種運算prekey用來保存前次進行何種運算
?? boolean?clear?=?false;?
?? String?copy;?//做復制用?
?? JTextArea?help;?//幫助?
?? JScrollPane?scrollHelp;
?? static?boolean?One?=true;?
??
??
??
????//******************//
?? //*****構造函數開始*****//
?? public?Calculator()?
?? {?
???? clickable?=?true;?
???? answerd?=?0;?
???? frame?=?new?Jframe(“夢幻計算器--SWE08008“);?
???? frame.setResizable(false);//不允許改變計算器的大小
???? frame.setLocation(250150);//設置計算器的起始位置
???? frame.setBackground(Color.YELLOW);???? ?? ?
???? df?=?new?DecimalFormat(“0.##############“);?//設置數據輸出精度(對于double型值)?
???? textAnswer?=?new?JTextField(“0“);?
???? textAnswer.setHorizontalAlignment(JTextField.RIGHT);//設置使數字居右????
???? textAnswer.setText(“0“);?
???? //textAnswer.setBackground(Color.pink);//設置輸出顯示框的背景顏色
???? textAnswer.setSelectionColor(Color.white);//設置選擇部分的顏色
???? textAnswer.setEditable(false);?//把輸出顯示框定義為不可寫
???? textAnswer.setBackground(new?Color(182174174));?//設置輸出顯示框的背景顏色
???? panel?=?new?JPanel();?
???? frame.getContentPane().add(panel);?
???? panel1?=?new?JPanel();?
???? panel2?=?new?JPanel();?
???? panel.setLayout(new?BorderLayout());
???? ?
???? //***設計整個面板***
???? //*********將所有行為與監聽綁定**********?
???? //*設置菜單*?
???? mainMenu?=?new?JMenuBar();?
???? editMenu?=?new?JMenu(“編輯(E)“);?
???? viewMenu?=?new?JMenu(“查看(V)“);?
???? helpMenu?=?new?JMenu(“幫助(H)“);?
???? //***編輯
???? copyItem?=?new?JMenuItem(“?復制(C)?Ctrl+C“);?
???? copyItem.addActionListener(this);?
???? pasteItem?=?new?JMenuItem(“?粘貼(V)?Ctrl+V“);?
???? pasteItem.
- 上一篇:基于java的p2p文件傳輸代碼.rar
- 下一篇:算術算法壓縮實現Java
評論
共有 條評論