JAVA 程序求 改错,总是编译错一个,各位帮帮忙
答案:3 悬赏:20 手机版
解决时间 2021-11-17 14:14
- 提问者网友:记得曾经
- 2021-11-16 13:25
JAVA 程序求 改错,总是编译错一个,各位帮帮忙
最佳答案
- 五星知识达人网友:枭雄戏美人
- 2021-11-16 13:58
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();
}
}
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();
}
}
全部回答
- 1楼网友:不甚了了
- 2021-11-16 15:26
兄弟, 建议用eclipse写java、很省心
- 2楼网友:空山清雨
- 2021-11-16 14:17
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("中文");
}
}
只能说无语了!好好看看书,好好看看书!
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("中文");
}
}
只能说无语了!好好看看书,好好看看书!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯