import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.TextField;
import java.awt.Color;
import javax.swing.JTextField;
import java.awt.TextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Button;
import javax.swing.JTree;
import javax.swing.JLabel;
public class Demo extends JFrame {
private JTextField txt=new JTextField();
private JPanel contentPane;
double text1=0;
double text2=0;
final TextField textField,textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Demo frame = new Demo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Demo() {
/* final double text1;
final double text2;
final TextField textField,textField_1;*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setToolTipText("");
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new TextField();
textField.setBounds(68, 61, 99, 23);
contentPane.add(textField);
if(textField.getText()!=null&&textField.getText().length()>0){
text1=Double.parseDouble(textField.getText().trim());
}
textField_1 = new TextField();
textField_1.setBounds(247, 61, 99, 23);
contentPane.add(textField_1);
if(textField_1.getText()!=null&&textField_1.getText().length()>0){
text2=Double.parseDouble(textField_1.getText().trim());
}
Button add = new Button("+");
add.setBounds(68, 115, 33, 23);
contentPane.add(add);
add.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
txt.setText(text1+text2+"");
}
});
Button button_1 = new Button("-");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txt.setText((text1-text2)+"");
}
});
button_1.setBounds(139, 115, 33, 23);
contentPane.add(button_1);
Button button_3 = new Button("/");
button_3.setBounds(313, 115, 33, 23);
contentPane.add(button_3);
Button button_4 = new Button("*");
button_4.setBounds(247, 115, 33, 23);
contentPane.add(button_4);
txt.setBounds(68, 166, 278, 23);
contentPane.add(txt);
JButton btnNewButton = new JButton("清零");
btnNewButton.setBounds(68, 209, 73, 23);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("退出");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton_1.setBounds(273, 209, 73, 23);
contentPane.add(btnNewButton_1);
JLabel label = new JLabel("请输入两个运算数据");
label.setBounds(68, 10, 130, 45);
contentPane.add(label);
}
}
相关分类