您的位置:首页 > 移动开发

JAVA入门2--关于JOptionPane 和 JApplet一起使用的方法例子

2008-09-19 14:12 736 查看
以前对于JOptionPane ,为JOptionPane.showInputDialog, JOptionPane.showMessageDialog ,输入和显示 数据。

 

而 JApplet 经常和 JLabel ,JTextField,JTextArea 作为使用。

 

现在把两块合并起来,在showInputDialog中输入字符,在JTextArea 显示出来。

 

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

 public class J35 extends JApplet {
       JTextArea  A1;
         int shuzhu[ ];
       public void init()
       {
        Container  contn = getContentPane();
        contn.setLayout( new FlowLayout() );

        A1 = new JTextArea(); 

        String input;
        int changdu, num1;
        input = JOptionPane.showInputDialog(" please input ");
        changdu = input.length();
        num1 = Integer.parseInt( input );    
        shuzhu = new int[ changdu ];
        displayDigits( changdu, num1 );
        contn.add( A1 );
         }      
       public void displayDigits( int x, int y )
       {
         for ( int i = 0; i < x; i++ )
         {
            shuzhu[ i ] = y % 10;
            y = y / 10;
          }
         
         for ( int j = x -1; j >= 0; j-- )
         {
            A1.append( shuzhu[ j ] + " " );
          }             
        }
    }  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java input import string class