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

📄 frm.java

📁 数据库实验报告
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class frm extends Frame implements ActionListener{
	
	Label lab1,lab2,lab3,lab4;
	TextField txt1;
	Button btn1,btn2,btn3;
	
	frm()
	{
		pack();
		this.setTitle("四则运算");
		this.setBounds(200,200, 380, 200);
		//this.setResizable(false);
		this.setVisible(true);
		this.setLayout(null);
		
		lab1=new Label();           //标签,提示用户输入表达式
		lab1.setBounds(15, 50, 80, 25);
		lab1.setText("请输入表达式:");
		//lab1.setBackground(Color.blue);
		
		
		lab2=new Label();            //标签,提示运算结果
		lab2.setBounds(15, 115, 80, 25);
		lab2.setText("运算结果为:");
		//lab2.setBackground(Color.pink);
		
		lab3=new Label();             //标签,显示运算结果
		lab3.setBounds(110, 115, 80, 25);
		lab3.setBackground(Color.pink);
		
		lab4=new Label("(请输入正确的表达式并以#号结束,不包含括号)");            //标签,注释
		lab4.setBounds(15, 80, 275, 25);
		lab4.setBackground(Color.pink);
		
		txt1=new TextField();     //输入运算表达式
		txt1.setBounds(110, 50, 180, 25);
		
		btn1=new Button("确定");         //确定
		btn1.setBounds(80,155, 60, 25);
		
		
		btn2=new Button("清空");         //清空
		btn2.setBounds(180, 155, 60, 25);
		
		 
		btn3=new Button("退出");         //退出
		btn3.setBounds(280, 155, 60, 25);
		
		
		
		
		add(lab1);
		add(lab2);
		add(lab3);
		add(lab4);
		add(btn1);
		add(btn2);
		add(btn3);
		add(txt1);
		btn1.addActionListener(this);      
		btn2.addActionListener(this);
		btn3.addActionListener(this);
		addWindowListener(new WindowAdapter(){  
	           public void windowClosing (WindowEvent e){  
	                dispose(); //释放由此 Window、其子组件及其拥有的所有子组件所使用的所有本机屏幕资源
	            }});  
		
		
	}
	
	public void actionPerformed(ActionEvent e) {
		
		if(e.getActionCommand()=="退出")     //退出
		{
			System.exit(0);			
		}
		else if(e.getActionCommand()=="确定")          //计算表达式
		{
			calculate cal=new calculate(txt1.getText());   
			
			int a=cal.AddSub();
			lab3.setText(a+"");    
			
		}
		else if(e.getActionCommand()=="清空")            //清空表达式
		{
			txt1.setText(null);
			lab3.setText(null);
		}
		
		
	}
	
	
	public static void main(String[] args) {
		
		frm f1=new frm();
		

	}

	
	

}

⌨️ 快捷键说明

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