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

📄 j02323.java

📁 摄氏与华氏温度转换实现两种温度的相互转换
💻 JAVA
字号:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;





class ButtonFrame extends Button  //定义按扭子类
{
	ButtonFrame(String s)
	{
		 super(s);//调用父类的默认函数

       setSize(100,400);//想改变按扭大小结果没成功


	}
}

public class J02323 extends Applet  implements ActionListener
{
	Label prompt1,prompt2;
	TextField input1,input2;
	double double1,double2;
	ButtonFrame bun1,bun2,bun3,bun4;
	 Font fnt= new Font("serief",Font.BOLD,12);     //定义字体类型和大小

	public void init()
	{
		setLayout(new FlowLayout(FlowLayout.LEFT,0,10));//设置空件排列方式即从左到右从上到下和它们的水平和垂直距离
		prompt1=new Label("摄氏温度:");
		prompt2= new Label("华氏温度:");
		input1= new TextField(10);
		input2=new TextField(10);
		bun1=new ButtonFrame("      转华氏        ");
		bun2=new ButtonFrame("      转摄氏        ");
		bun3=new ButtonFrame("      退   出        ");
		bun4=new ButtonFrame("       清   除         ");
		bun1.setFont(fnt);
		bun2.setFont(fnt);
		bun3.setFont(fnt);
		bun4.setFont(fnt);
		add(prompt1);
		add(input1);
		add(prompt2);
		add(input2);

		add(bun1,BorderLayout.WEST);             //设置按扭边界布局
		add(bun2,BorderLayout.EAST);
		add(bun3,BorderLayout.CENTER);
		add(bun4);
		input1.addActionListener(this);          //给按扭和文本框加事件监听器
		input2.addActionListener(this);
		bun1.addActionListener(this);
		bun2.addActionListener(this);
		bun3.addActionListener(this);
		bun4.addActionListener(this);
	}

public void paint(Graphics g)
{
	setSize(200,300);
    setBackground(Color.green);
	setLocation(10,10);
}

public void  actionPerformed(ActionEvent e)
	{
		if(e.getSource()==bun1||(e.getSource()==input1))           //响应鼠标和键盘两种操作
		{
			double1=Double.valueOf(input1.getText()).doubleValue();    //提取输入内容转化为double型
			double2=(double1*9)/5+32;                         // 根据公式转换
			//input1.setText("");
			input2.setText(Double.toString(double2));
		}
		else
		    if(e.getSource()==bun2||(e.getSource()==input2))//响应鼠标和键盘两种操作
		    {
				double2=Double.valueOf(input2.getText()).doubleValue();//提取输入内容转化为double型
			    double1=Math.round(5*(double2-32)/9);         // 根据公式转换
				input1.setText(Double.toString(double1));
			    //input2.setText( "");
			}
			else
			{
				if(e.getSource()==bun3)

				System.exit(0);
				else
				{
					input1.setText("");
					input2.setText("");
				}
			}

		}
	}



⌨️ 快捷键说明

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