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

📄 e10_3.java

📁 几个不错的程序 是本人好多天的结果 真的和不错呀 适合java的学习
💻 JAVA
字号:
/**
 * @(#)E10_3.java
 *
 * Sample Applet application
 *
 * @author 
 * @version 1.00 06/10/26
 */
 
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class E10_3 extends Applet implements ActionListener
{
	double x,y;
	double z;
	TextField text1,text2,text3;
	Button button1,button2,button3,button4;
	public void init()
	{
		setBackground(Color.yellow);
		text1=new TextField(10);
		text2=new TextField(10);
		text3=new TextField(10);
		text3.setEditable(false);
		//text3.setBackground(Color.pink);
		button1=new Button("加");
		button2=new Button("差");
		button3=new Button("积");
		button4=new Button("除");
		button1.addActionListener(this);
		button2.addActionListener(this);
		button3.addActionListener(this);
		button4.addActionListener(this);
		add(new Label("请输入x的值:"));
		add(text1);
		add(new Label("请输入y的值:"));
	   // button1.setBackground(Color.pink);
	//	button2.setBackground(Color.cyan);
	//	button3.setBackground(Color.blue);
	//	button4.setBackground(Color.yellow);
		add(text2);
		add(text3);
		
		add(button1);
		add(button2);
		add(button3);
		add(button4);
	}
	public void actionPerformed(ActionEvent e)
	{
		try
		{
			 x=Double.parseDouble(text1.getText());
		     y=Double.parseDouble(text2.getText());
			
			if(e.getSource()==button1)
		    {  
		        //z=x+y;
		     	text3.setText(x+"+"+y+"="+(x+y));
	    	}
		    if(e.getSource()==button2)
		    {
		     	z=x-y;
		    	text3.setText(x+"-"+y+"="+z);
	    	}
	     	if(e.getSource()==button3)
	    	{
		      	z=x*y;
			text3.setText(x+"*"+y+"="+z);
		    }
		   if(e.getSource()==button4)
	       {
	       	if(y!=0)
			  { z=x/y;
			   text3.setText(x+"/"+y+"="+z);
			   }
			   else text3.setText("除数为0");
			}
		
	   	}
		catch(NumberFormatException ee)
		{
			text3.setText("请输入数字字符");
		
			
		}   
		
		
		
	}

	
}

⌨️ 快捷键说明

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