永发信息网

JAVA 程序求 改错,总是编译错一个,各位帮帮忙

答案:3  悬赏:20  手机版
解决时间 2021-11-17 14:14
JAVA 程序求 改错,总是编译错一个,各位帮帮忙
最佳答案
import java.awt.*;

import javax.swing.*;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;

public class Moneyc extends JFrame implements CaretListener
{

private JTextField text_money,text_word;
private MessageJDialog jdialog;

public Moneyc()
{
super("中文");
this.setBounds(300,240,320,100);
this.setResizable(false);
this.setBackground(java.awt.Color.lightGray);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT));

this.getContentPane().add(new JLabel("金额"));
text_money=new JTextField("12345.67",20);
//text_money.setHorizontalAlignment(JTextField.RIGHT);
this.getContentPane().add(text_money);
text_money.addCaretListener(this);

this.getContentPane().add(new JLabel("中文形式"));
text_word=new JTextField(20);
//text_word.setHorizontalAlignment(JTextField.RIGHT);
text_word.setEditable(false);
this.getContentPane().add(text_word);
caretUpdate(null); //执行文本编辑事件
this.setVisible(true);
jdialog=new MessageJDialog(this);

}
private class MessageJDialog extends JDialog
{
private JFrame jframe;
private JLabel jlabel;
public MessageJDialog(JFrame jframe)
{
super(jframe, "提示",true);
this.jframe=jframe;
this.setSize(300,80);
jlabel=new JLabel("",JLabel.CENTER);
this.getContentPane().add(jlabel);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

public void show(String message)
{
jlabel.setText(message);
this.setLocation(jframe.getX()+100,jframe.getY()+100);
this.setVisible(true);
}
}

public void caretUpdate(CaretEvent e)
{
try
{
double x=Double.parseDouble(text_money.getText());
text_word.setText(RMBtoString(x));
}
catch(NumberFormatException nfe)
{
jdialog.show("\""+text_money.getText()+"\" 不能转换!" );

}
finally{}
}
public static String RMBtoString(double x)
{
String yuan="亿千百拾万千拾元角分";
String digit="零一二三四五六七八九";
String result="";
int y=(int)Math.round(x*100-0.5);
int i=yuan.length()-1;
while(y>0 && i>0)
{
result=""+digit.charAt(y%10)+yuan.charAt(i)+result;
i--;
y=y/10;

}
return result;

}

public static void main(String arg[])
{
new Moneyc();

}

}
全部回答
兄弟, 建议用eclipse写java、很省心
import java.awt.*;
import javax.swing.*;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;

public class gg extends JFrame implements CaretListener{

private JTextField text_money,text_word;
private MessageJDialog jdialog;

public gg(String x)
{

super(x);
this.setBounds(300,240,320,150);
this.setResizable(false);
this.setBackground(Color.lightGray);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT));

this.add(new JLabel("金额"));
text_money=new JTextField("12345.67",30);
text_money.setHorizontalAlignment(JTextField.RIGHT);
this.add(text_money);
text_money.addCaretListener(this);

this.add(new JLabel("中文形式"));
text_word=new JTextField(30);
text_word.setHorizontalAlignment(JTextField.RIGHT);
this.add(text_word);
text_word.setEditable(false);
this.setVisible(true);
jdialog=new MessageJDialog(this);

}

private class MessageJDialog extends JDialog{

JFrame jframe;
JLabel jlabel;
MessageJDialog(JFrame jframe)
{
super(jframe,"提示",true);
this.jframe=jframe;
this.setSize(300,80);
JLabel jlable=new JLabel("",JLabel.CENTER);
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)
{
try
{

double y=Double.parseDouble(text_money.getText());

text_word.setText(RMBtostring(y));

}

catch(NumberFormatException nfe)
{
jdialog.show("\""+text_money.getText()+"\"不能转换!");
}
finally{}

}

public static String RMBtostring(double x)
{
String yuan="亿千百拾万千拾角分";
String digit="零一二三四五六七八九";
String result="";
int y=(int)Math.round(x*100-0.5);
int i=yuan.length()-1;
while(y>0&&i>0);
{
result=""+digit.charAt(y%10)+yuan.charAt(i)+result;
i--;
y=y/10;

}
return result;

}

public static void main(String arg[])
{
new gg("中文");
}

}

只能说无语了!好好看看书,好好看看书!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
女性长期掉发的原因是什么,用松露疗法可以解
高约2米,若每立方米砂重2吨,这堆砂约重多少
我想请教一下 国标的 150平方米电缆*3+2 有多
俄罗斯总统普京妻子吗
太极禅的太极历史
有谁能闻到春、夏、秋、冬这四个季节的味道
的,转行做岩土工程怎么样
vivoX9plus屏幕碎了,原装的和非原装的会有很
A+网络生活馆地址好找么,我有些事要过去,
MTK的手机要怎么连接电脑?就是可以看见手机
和70除以7相同的数的算式
为什么用笔记本玩GTA5会出现水波纹
(-56)×32+44×(-32)
什么是polite word(具体点)
网上传1945年上海穷人只能吃大闸蟹勉强度日,
推荐资讯
玉皇大帝第九个女儿
江山如画下一句
靖边县鼎宏汽贸有限公司地址在哪,我要去那里
亲我想问。我已婚想买房子可以不让对象知道吗
巧笑倩兮,下一句是什么
赖老师再论经典的次第,到底是经先,还是典先
度娘的台词太讽刺了吧?我知道,因为你知道。
鼻孔周边长脓,怎么办,能挑开吗
大连劳动公园相亲会找对象靠谱吗?
1998年老十块值多少钱
BMX南海离合轴
有关香味的成语
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?