- package change;
- import javax.swing.*;
- import java.awt.FlowLayout;
- import javax.swing.JTextField;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class text extends JFrame implements ActionListener{
- int a ;
- JTextField jfd1=new JTextField(9);
- JTextField jfd2=new JTextField(9);
- JButton jbt1=new JButton("确定");
- FlowLayout fly=new FlowLayout();
- text(){
- super("测试");
- setSize(300,300);
- setLocation(300,300);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.getContentPane().add(jfd1);
- this.getContentPane().add(jfd2);
- this.getContentPane().add(jbt1);
- this.getContentPane().setLayout(fly);
- jbt1.addActionListener(this);
- show();
- }
- public void actionPerformed(ActionEvent actionEvent) {
- }
- public void actionPerformes(ActionEvent e){
- if(e.getSource()==jbt1){
- String str =jfd1.getText();
- try {
- a = Integer.parseInt(str);
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- Double b = new Double(a);
- jfd2.setText(b.toString());
- }
- }
- public static void main(String[] args) {
- text tex=new text();
- }
- }
复制代码 |
|