以前对于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 ] + " " );
}
}
}