package 实验包;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Example1 extends JFrame{
public Example1(){
JFrame jf=new JFrame();
Container container=jf.getContentPane();
container.setLayout(null);
jf.setVisible(true);
jf.setSize(320,300);
JButton button1=new JButton("+");
JButton button2=new JButton("-");
JButton button3=new JButton("*");
JButton button4=new JButton("/");
JTextField text1=new JTextField();
JTextField text2=new JTextField();
button1.setBounds(0,200,75,50);
button2.setBounds(75,200,75,50);
button3.setBounds(150,200,75,50);
button4.setBounds(225,200,75,50);
container.add(button1);
container.add(button2);
container.add(button3);
container.add(button4);
text1.setBounds(0,0,300,100);
text2.setBounds(0,100,300,100);
container.add(text1);
container.add(text2);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String x1=text1.getText();
String x2=text2.getText();
double y1=Double.parseDouble(x1);
double y2=Double.parseDouble(x2);
double z=y1+y2;
text1.setText(z+"");
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String x1=text1.getText();
String x2=text2.getText();
double y1=Double.parseDouble(x1);
double y2=Double.parseDouble(x2);
double z=y1-y2;
text1.setText(z+"");
}
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String x1=text1.getText();
String x2=text2.getText();
double y1=Double.parseDouble(x1);
double y2=Double.parseDouble(x2);
double z=y1*y2;
text1.setText(z+"");
}
});
button4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String x1=text1.getText();
String x2=text2.getText();
double y1=Double.parseDouble(x1);
double y2=Double.parseDouble(x2);
double z=y1/y2;
text1.setText(z+"");
}
});
}
public static void main(String[] args) {
new Example1();
} }