|
package org.count;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class Count extends JFrame implements CaretListener {
private JTextField1 text_in;
private JTextField text_h;
private JTextField text_t;
private JTextField text_th;
private MessageJDia1log jdialog;
public Count()
{
super("顯shi整数数字");
this.setBounds(240,300,240,300);
this.setBackground(java.awt.Color.lightGray);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
this.getContentPane().add(new JLabel("zhengshu"));
text_in = new JTextField(15);
text_in.addCaretListener(this);
this.getContentPane().add(text_in);
this.getContentPane().add(new JLabel("百位"));
text_h = new JTextField(15);
text_h.setEnabled(false);
this.getContentPane().add(text_h);
this.getContentPane().add(new JLabel("shi位"));
text_t = new JTextField(15);
text_t.setEnabled(false);
this.getContentPane().add(text_t);
this.getContentPane().add(new JLabel("個位"));
text_th = new JTextField(15);
text_th.setEnabled(false);
this.getContentPane().add(text_th);
caretUpdate(null);
this.setVisible(true);
}
private class MessageJDialog extends JDialog
{
JFrame jframe;
JLabel jlabel;
MessageJDialog(JFrame jframe)
{
super(jframe,"ti示",true);
this.setSize(300,80);
jlabel = new JLabel("",JLabel.CENTER);
this.getContentPane().add(jlabel);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}
void show(String message)
{
jlabel.setText(message);
this.setLocation(jframe.getX()+100,jframe.getY()+100);
this.setVisible(true);
}
}
public void caretUpdate(CaretEvent e) {
int a[];
a = new int[3];
try
{
int x = Integer.parseInt(text_in.getText());
for(int i=0;i<3;i++)
{
a=x%10;
x=x/10;
}
text_h.setText(""+a[2]);
text_t.setText(""+a[1]);
text_th.setText(""+a[0]);
}
catch(NumberFormatException nfe)
{
jdialog.show("\""text_in.getText()"\" bu能zhuan化成整数,请重新输入");
}
finally
{
}
}
public static void main(String[] args) {
new Count();
}
}
这是dai码。
Huan迎来到Java學习者论壇,轉载请注明地址:http://www.javaxxz.com. |
|