首页 > 代码库 > java的图像界面

java的图像界面

package test;


import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Mygoods {

    public static void main(String[] args){
        new AppFrame();
        
    }
}

class AppFrame extends JFrame
{
    JTextField inField = new JTextField(10);
    JButton jButton  =new JButton("求平方");
    JLabel jLabel = new JLabel("显示结果");
    
    
    public AppFrame () {
        setLayout(new FlowLayout());
        getContentPane().add(inField);
        getContentPane().add(jButton);
        getContentPane().add(jLabel);
        
        jButton.addActionListener(new BtnActionAdapter());
        setSize(400,400);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setVisible(true);
    }
    class BtnActionAdapter implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            String s= inField.getText();
            double d=Double.parseDouble(s);
            double sq=d*d;
            jLabel.setText(d+"平方是"+sq);
        }
    }
}

 

java的图像界面