正文

本人的文本输入(目前只有分数文本可用)2006-04-02 23:59:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sword2008/11882.html

分享到:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 

public class ButtonTest1 extends JFrame{
 private JButton aB,bB,exitButton,qrButton;
 
 private JLabel mz,fs;
 
 private JTextField mz1,fs1;
 
 public String mzsz[]=new String[20];
 public int fssz[]=new int[20];
 
 public ButtonTest1(){
  super("testing buttons");
  Container container=getContentPane();
  container.setLayout(new FlowLayout());
  
  aB=new JButton("输入学生姓名和分数");
  container.add(aB);
  
  //ButtonHandler handler=new ButtonHandler();
  bB=new JButton("退出");
  container.add(bB);
  
  ButtonHandler handler=new ButtonHandler();
  
  aB.addActionListener(handler);
  bB.addActionListener(handler);
  
  setSize(800,256);
  setVisible(true);
 }
 
 public static void main(String args[]){
  ButtonTest1 application=new ButtonTest1();
  application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
 }
 
 
 void TimeTestWindow(){
 JFrame frame=new JFrame("名字和分数的输入");
 Container container=frame.getContentPane();
 container.setLayout(new FlowLayout());
 
 mz=new JLabel("名字:");
 mz1=new JTextField(10);
 container.add(mz);
 container.add(mz1);
 
 fs=new JLabel("分数:");
 fs1=new JTextField(10);
 container.add(fs);
 container.add(fs1);
 
    qrButton=new JButton("确认          ");
 container.add(qrButton);
 
 exitButton=new JButton("直接退出");
 container.add(exitButton);
  
 //setSize(800,256);
    //setVisible(true);
   
    frame.setSize(800,256);   //修改处
    frame.setVisible(true);   //修改处
   
    ButtonHandler handler=new ButtonHandler();
   
    mz1.addActionListener(handler);
    fs1.addActionListener(handler);
    exitButton.addActionListener(handler);
    qrButton.addActionListener(handler);
   
 
}


 private class ButtonHandler implements ActionListener{
  public void actionPerformed(ActionEvent event){
    int i=0;
   
   
   if(event.getSource()==bB)
   System.exit(0);
   else
    if(event.getSource()==exitButton)
   System.exit(0);
    else
      if(event.getSource()==qrButton)
     //if(event.getSource()==mz1)
   //   mzsz[i]=event.getActionCommand();
     // else if(event.getSource()==fs1)
     {

      fssz[i]=Integer.parseInt(fs1.getText());
      i++ ;
     
      //System.out.println(mzsz[i]+fssz[i]);
      JOptionPane.showMessageDialog(null,mzsz[i]+fssz[i-1],"测试结果",JOptionPane.INFORMATION_MESSAGE);}
     
     else
    
     TimeTestWindow();
    

 }
}
}

阅读(4736) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册