⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例8-4.java

📁 医院无线局域网设计方案 医院无线局域网设计方案
💻 JAVA
字号:
//example 8-4
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class tt extends Applet implements ActionListener
{
   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);
   	 btnExit.addActionListener(this);
   	 btnRun.addActionListener(this);
   	 p3.add(btnExit);p3.add(btnRun);
   	 add("North",p1);add("Center",p2);add("South",p3);
   }
   public void actionPerformed(ActionEvent evt)
   {
   	  int temp;
   	  temp=Integer.parseInt(txtIntro.getText());
   	  
   	  if(evt.getActionCommand()=="Exit")
   	     System.exit(0);
   	  else if(evt.getActionCommand()=="Run")
   	  {
   	  	 int sum=0;
   	  	 for(int i=1;i<=temp;i++)
   	  	    sum=sum+i;
   	  	 txtResult.setText(String.valueOf(sum));
   	  }
   }
   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();
      //setVisible(true);
      this.addWindowListener(new closeWindows());
   }
}
class closeWindows extends WindowAdapter
{
   public void windowClosing(WindowEvent e)
   {
   	  Frame frm=(Frame)(e.getSource());
   	  frm.dispose();
   	  System.exit(0);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -