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

📄 mycalc.java

📁 classical culculator but has some thing special that you can store your work in a file in the hard a
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			pressed=true;			memoryTag.setText("M");			mem=Double.valueOf(s).doubleValue();			if(mem==0)				memoryTag.setText(" ");			showStatus("Memory="+mem);		}		else if(e.getSource()==button[36])		{			pressed=true;			memoryTag.setText("M");			mem=mem+(Double.valueOf(s).doubleValue());			if(mem==0)				memoryTag.setText(" ");			showStatus("Memory="+mem);		}		else if(e.getSource()==button[38])		{			pressed=true;			memoryTag.setText("M");			mem=mem-(Double.valueOf(s).doubleValue());			if(mem==0)				memoryTag.setText(" ");			showStatus("Memory="+mem);		}		else if(e.getSource()==button[39])		{			s=""+mem;			s3=s;			t.setText(s3);		}		else if(e.getSource()==button[20])		{			pressed=true;			double x=Double.valueOf(s).doubleValue();			String s4 = deg.getSelectedCheckbox().getLabel();			if (!cond3)			{			if(s4.equals("Deg"))			{				while(x>=360)				 		x=x-360;				s=""+MyMath.msin(MyMath.invert(x));				t.setText(""+s);			}			else if(s4.equals("Rad"))			{				while(x>=(2*Math.PI))				 		x=x-Math.PI;									s=""+MyMath.msin(x);				t.setText(s);			}			f.addTofile("Sin("+x+")="+s);			}			else			{			if(s4.equals("Deg"))			{				x=Double.valueOf(s).doubleValue();				s=""+MyMath.invertt(Math.asin(x));				t.setText(""+s);			}			else if(s4.equals("Rad"))			{				x=Double.valueOf(s).doubleValue();				s=""+MyMath.invertt(Math.acos(x));				t.setText(s);			}				s3=s;				f.addTofile("aSin("+x+")="+s);			}		}		else if(e.getSource()==button[21])		{			pressed=true;			double x=Double.valueOf(s).doubleValue();			String s4 = deg.getSelectedCheckbox().getLabel();			if (!cond3)			{				 if(s4.equals("Deg"))				 {				 		while (x>=360)				 			x=x-360;					 	s=""+MyMath.mcos(MyMath.invert(x));				 	 	t.setText(s);						s3=s;				}				 else if(s4.equals("Rad"))				 {				 	while(x>=(2*Math.PI))				 		x=x-Math.PI;					 s=""+MyMath.mcos(x);				 	t.setText(s);					s3=s;				}			f.addTofile("Cos("+x+")="+s);			}				else				{					if(s4.equals("Deg"))					{						x=Double.valueOf(s).doubleValue();						s=""+MyMath.invertt(Math.acos(x));						t.setText(s);						s3=s;					}					else if(s4.equals("Rad"))					{						x=Double.valueOf(s).doubleValue();						s=""+MyMath.invertt(Math.acos(x));						t.setText(s);						s3=s;					}			f.addTofile("aCos("+x+")="+s);			}	    	}	    else if(e.getSource()==button[23])	    {	    		 pressed=true;	    		 double y=0;				 double  x=Double.valueOf(s).doubleValue();				 y=MyMath.mysqr(x);				 t.setText(""+y);				 s=""+y;				 s3=s;				 f.addTofile("sqr("+x+")="+s);		}		else if(e.getSource()==button[24])	    {		   	 pressed=true;			 int x=Integer.valueOf(s).intValue();			 if(x>39)			 	t.setText("Invinit");			 else			 {			 	s=""+MyMath.myX(x);			 	t.setText(""+s);			 	s3=s;			 	f.addTofile(""+x+"!="+s);			 }		}		else if(e.getSource()==button[2])		{			if(!cond3)				{					button[20].setLabel("arcSin");					button[21].setLabel("arcCos");					cond3=true;				}			else				{					cond3=false;					button[20].setLabel("Sin");					button[21].setLabel("Cos");				}		}		else if(e.getSource()==button[40])		{			t.setText("0");			mem=0;			memoryTag.setText("");		}		else if(e.getSource()==button[26])		{			pressed=true;			float p,r;			p=Float.valueOf(s).floatValue();			r=p/100;			s=""+r;			s3=s;			t.setText(s);			f.addTofile(""+p+"%="+s);		}		else if(e.getSource()==button[22])		{			pressed=true;			 double l=0;			 m=Double.valueOf(s).doubleValue();			 l=Math.sqrt(m);			 s=""+l;			 s3=s;			 t.setText(s);			 f.addTofile("sqrt("+m+")="+s);		}		else if (e.getSource()==button[19])		{			pressed=true;		  	t.setText(s3);			s=s3;			showStatus(s3);		}		else if (e.getSource()==button[17])		{			pressed=true;			t.setText(""+3.1415926);			s=""+3.1415926;		}    }  public static void main(String args[])		{			Frame app=new Frame("Calculator");			app.setSize(470,400);			app.addWindowListener(new CloseWindowAndExit());			MyCalc m=new MyCalc();			m.init();			m.start();			app.add(m,BorderLayout.CENTER);			app.setVisible(true);	}        class MyButton extends Button    {	public MyButton(String name,Color xyz)	{//here we override the constructor of the button //first we call the Main constructor and then//we add the color proprty and response for mouse motion		super(name);		setBackground(xyz);		addMouseListener(new MouseCalcButtonAdapter());	}	class MouseCalcButtonAdapter extends MouseAdapter	{		Color color;		public void mouseEntered(MouseEvent me)		{			color=me.getComponent().getBackground();			setForeground(Color.red);			setBackground(Color.black);			setFont(new Font("Courier New",Font.BOLD,12));		}		public void mouseExited(MouseEvent me)		{			setFont(new Font("Courier New",Font.BOLD,10));			setForeground(Color.black);			me.getComponent().setBackground(color);		}	}   }   class MyFile   //MyFile is inner class   {   	private DataOutputStream Of;   	public void WriteFileOnTextArea() 	{          String str;          char st;          str="";      try      {        DataInputStream If=new DataInputStream(new FileInputStream("FileOutput.txt"));        while(If.readLine()!=null)        {        	if ((st=If.readChar())!='E')        	{          		str=st+str;          	}          	if (st=='E')          	{          		ta.append(str);          		ta.append("\n");          		str="";          	}      	}      	If.close();      }    catch(FileNotFoundException e) {}    catch(IOException e) {}	}	public void CreateFile()	{ 		try 		{    	Of=new DataOutputStream(new FileOutputStream("FileOutput.txt"));    	Of.writeChars("Begin\n");    	}    	catch(IOException e) {    		System.err.println("File not opened properly\n"+e.toString());            System.exit(1);    	}	}	public void addTofile(String str)	{		try		{			for(int i=str.length()-1;i>=0;i--)			{				Of.writeChar(str.charAt(i));				Of.writeChars("\n");			}			Of.writeChar('E');			Of.writeChars("\n");		}		catch (IOException io){}	}	public void delFile()	{		 	CreateFile();			try			{				Of.close();			}			catch (IOException io){}	}	public void endStore()	{			try			{				Of.close();			}			catch (IOException io){}	}}}class MyMath{		public static double msin(double x)		{		if (x<=0.0005)		 x=x+((x*x*x)/6);		else		 x=2*msin(x/2)*mcos(x/2);		return x;		}		public static double mcos(double x)		{		if (x<=0.0005)		 x=1-((x*x*x)/2);		else		 x=(mcos(x/2)*mcos(x/2))-(msin(x/2)*msin(x/2));		return x;	}		public static double invertt(double x)		{//converting from radian to degree 						double y;			y=(180*x)/Math.PI;			return y;		}	public static double invert(double x)	{//converting from degree to radian 		double y;		y=(Math.PI*x)/180;		return y;	}	public static double mypow(double x,int y)	{		double s;		s=1;		for(int i=1;i<=y;i++)			s=s*x;		return s;	}	public static double mysqr(double x)	{		double s=x*x;		return s;	}	public static long myX(int x)//factorial function		{		long t=1;		for(int i=x;i>0;i--)			t=i*t;		return t;	}} class CloseWindowAndExit  implements WindowListener{	public void windowClosing(WindowEvent e)	{		System.exit(0);	}	public void windowActivated(WindowEvent e){}	public void windowClosed(WindowEvent e){}	public void windowDeactivated(WindowEvent e){}	public void windowDeiconified(WindowEvent e){}	public void windowIconified(WindowEvent e){}	public void windowOpened(WindowEvent e){}}// end of the  project :// Programers:(the order was choosen by trusted random function)//Georg Elias//Bahaa Morad//Samer Al_Fakeh//Bahar Mhasin///End

⌨️ 快捷键说明

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