?? 例8-3.java
字號:
//example 8-3
import java.applet.Applet;
import java.awt.*;
public class tt extends Applet
{
Button btnExit=new Button("Exit");
Button btnRun=new Button("Run");
Label lblIntro=new Label("Please input positive integer here");
Label lblResult=new Label("The result is:");
TextField txtIntro=new TextField("0",10);
TextField txtResult=new TextField("0",10);
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
public void init()
{
resize(350,200);
p1.add(lblIntro);p1.add(txtIntro);
p2.add(lblResult);p2.add(txtResult);
p3.add(btnExit);p3.add(btnRun);
add("North",p1);add("Center",p2);add("South",p3);
}
public boolean action(Event evt,Object obj)
{
if(evt.target instanceof Button)
{
String btnName=(String)obj;
if(btnName.equals("Exit"))
System.exit(0);
else
{
int sum=0;
for(int i=1;i<=Integer.parseInt(txtIntro.getText());i++)
sum=sum+i;
txtResult.setText(String.valueOf(sum));
}
}
return super.action(evt,obj);
}
public static void main(String args[])
{
new ttFrame(new tt());
}
}
class ttFrame extends Frame
{
public ttFrame(Applet applet)
{
resize(400,400);add("Center",applet);
applet.init();
show();
}
public boolean handle(Event evt)
{
if(evt.id==Event.WINDOW_DEICONIFY)
System.exit(0);
return super.handleEvent(evt);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -