importjava.awt.*;importjavax.swing.*;publicclassmyframeextendsJFrame{publicmyframe(){super("sum");Containerc=getContentPane();c.setLayout(newFlowLayout());JTextFielda=new...
import java.awt.*;
import javax.swing.*;
public class myframe extends JFrame
{
public myframe()
{
super("sum");
Container c=getContentPane();
c.setLayout(new FlowLayout());
JTextField a=new JTextField(10);
JTextField b=new JTextField("+",1);
JTextField d=new JTextField(10);
JButton e=new JButton("=");
JTextField f=new JTextField(10);
e.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
String str2=a.getText();
String str3=d.getText();
double d1=Double.parseDouble(str2);
double d2=Double.parseDouble(str3);
double d3=d1+d2;
String str4=""+d3;
f.setText(str4);
}
});
b.setEditable(false);
c.add(a);
c.add(b);
c.add(d);
c.add(e);
c.add(f);
}
public static void main(String args[])
{
myframe app=new myframe();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(360,150);
app.setVisible(true);
} }
展开