结个长和宽,点击按钮出现周长与面积,这个方法怎么添加?源代码importjavax.swing.*;importjava.awt.GridLayout;publicclassShuzu{publicstaticvoidmain(String[]args){JFramea=newJ...
结个长和宽,点击按钮出现周长与面积,这个方法怎么添加?
源代码
import javax.swing.*;import java.awt.GridLayout;public class Shuzu { public static void main(String[]args){ JFrame a=new JFrame(); a.setVisible(true); a.setTitle("java"); a.setSize(420,320); a.setLocation(200,200); a.setResizable(false); a.setLayout(new GridLayout(10,5)); JLabel b=new JLabel("请输入长方形的长:"); a.add(b); JTextField b1=new JTextField(50); a.add(b1); JLabel c=new JLabel("请输入长方形的宽:"); a.add(c); JTextField c1=new JTextField(50); a.add(c1); JLabel f=new JLabel(); a.add(f); JButton d=new JButton("自动运算"); a.add(d); JLabel e=new JLabel("长方形的周长为:"); a.add(e); JTextField e2=new JTextField(50); a.add(e2); JLabel e1=new JLabel("长方形的面积为:"); a.add(e1); JTextField e3=new JTextField(50); a.add(e3); a.setVisible(true); }}
展开