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

📄 accountwidget.java

📁 Deployment of Server 1.install Tomcat(superior than j2sdk1.4.2 and Tomcat 5.0),and setup the env
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat;/**  * This class configures a GUI interface to the Account class. * It is used by both the applet and the standalone application. * @author   Ian A. Mason. * @version  1.1 * @since    March 2005 */class AccountWidget {  public static void configure(final Container cont){      final String answer = "Account balance = $";      final DecimalFormat formatter =  new DecimalFormat("#.##");      cont.setLayout(new FlowLayout());      Label alabel = new Label("Amount in Account (an int):", Label.CENTER);      alabel.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(alabel);         final TextField afield  = new TextField("0",12);      afield.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(afield);         Label rlabel = new Label("Interest Rate for Account (an float):", Label.CENTER);      rlabel.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(rlabel);         final TextField rfield  = new TextField("0.00", 4);      rfield.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(rfield);         Label tlabel = new Label("Length of Deposit (an int):", Label.CENTER);      tlabel.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(tlabel);         final TextField tfield  = new TextField("0", 4);      tfield.setFont(new Font("SansSerif", Font.PLAIN, 15));      cont.add(tfield);         final Button button = new Button("To Compute the Value of the Account -- Press Me!");      button.setFont(new Font("SansSerif", Font.PLAIN, 20));      button.setForeground(Color.blue);      cont.add(button);      final Label answerLabel = new Label(answer + 0 , Label.LEFT);      answerLabel.setFont(new Font("SansSerif", Font.PLAIN, 25));      cont.add(answerLabel);      /*        * note the use of an anonymous inner class to do the event       * handling, this explains why the awt widgets used in the body        * are declared final.       */      button.addActionListener(new ActionListener(){	      public void actionPerformed(ActionEvent ae){		  int   a = 0; 		  int   t = 0;		  float r = 0F;		  try{		      a = Integer.parseInt(afield.getText());		      r = Float.parseFloat(rfield.getText());		      t = Integer.parseInt(tfield.getText());		  }catch(NumberFormatException e){ }		  //Using the user (i.e. your version) defined Account class		  Account account = new Account(a,r);        		  answerLabel.setText(answer + formatter.format(account.getBalance(t)));		  cont.validate();	      }	  });  }}

⌨️ 快捷键说明

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