1个回答
展开全部
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class lifang extends Applet implements ActionListener
{
Label lbl1= new Label ("请输入数字");
Label lbl2= new Label ("此处显示结果");
TextField tf1 = new TextField (10);
Button btn = new Button ( "求立方");
public void init()
{
add (lbl1);
add (tf1);
add (btn);
add (lbl2);
this.resize(300,100);
btn.addActionListener (this);
}
public void actionPerformed (ActionEvent e)
{
String start = tf1.getText();
int result= Integer.parseInt(start) *Integer.parseInt(start)*Integer.parseInt(start)
lbl2.setText ("立方是:"+ result);
}
}
import java.awt.*;
import java.awt.event.*;
public class lifang extends Applet implements ActionListener
{
Label lbl1= new Label ("请输入数字");
Label lbl2= new Label ("此处显示结果");
TextField tf1 = new TextField (10);
Button btn = new Button ( "求立方");
public void init()
{
add (lbl1);
add (tf1);
add (btn);
add (lbl2);
this.resize(300,100);
btn.addActionListener (this);
}
public void actionPerformed (ActionEvent e)
{
String start = tf1.getText();
int result= Integer.parseInt(start) *Integer.parseInt(start)*Integer.parseInt(start)
lbl2.setText ("立方是:"+ result);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询