这个java程序怎么把计算的结果放入TextArea啊?
importjava.io.*;importjava,awt.*;importjava.awt.event.*;publicclassDollarToRenmingbie...
import java.io.*;
import java,awt.*;
import java.awt.event.*;
public class DollarToRenmingbi extends Frame{
String str;
final static double DOLLAR=6.9;
TextField tf=new TextField("Input a String");
TextArea ta=new TextArea();
public static void main(String[] args){
BufferedReader dos=new BufferedReader(new InputStreamReader(System.in));
str= dos.readLine();
int num=Integer.parseInt(str);
double R=num*DOLLAR;
System.out.println("Input a String: ");
System.out.println(R);
DollarToRenmingbi dtr=new DollarToRenmingbi();
dtr.lanuchFrame();
}
public void lanuchFrame(){
setLocation(200,300);
setSize(400,400);
setTitle("美元计算器 ");
setResizable(false);
setBackground(Color.GREEN);
setVisible(true);
this.add(tf,BorderLayout.SOUTH);
this.add(ta,BorderLayout.NORTH);
pack();
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.addActionListener(new TFListener());
}
private class TFListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ta.setText(R);
tf.setText("");
}
}
} 展开
import java,awt.*;
import java.awt.event.*;
public class DollarToRenmingbi extends Frame{
String str;
final static double DOLLAR=6.9;
TextField tf=new TextField("Input a String");
TextArea ta=new TextArea();
public static void main(String[] args){
BufferedReader dos=new BufferedReader(new InputStreamReader(System.in));
str= dos.readLine();
int num=Integer.parseInt(str);
double R=num*DOLLAR;
System.out.println("Input a String: ");
System.out.println(R);
DollarToRenmingbi dtr=new DollarToRenmingbi();
dtr.lanuchFrame();
}
public void lanuchFrame(){
setLocation(200,300);
setSize(400,400);
setTitle("美元计算器 ");
setResizable(false);
setBackground(Color.GREEN);
setVisible(true);
this.add(tf,BorderLayout.SOUTH);
this.add(ta,BorderLayout.NORTH);
pack();
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.addActionListener(new TFListener());
}
private class TFListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ta.setText(R);
tf.setText("");
}
}
} 展开
展开全部
final Frame frame = new Frame("Converter");
final Label from = new Label("From $:");
final Label to = new Label("To ¥:");
final TextField input = new TextField(10);
final TextField output = new TextField(10);
frame.setLayout(new GridLayout(4,1,5,5));
frame.add(from);
frame.add(input);
frame.add(to);
frame.add(output);
frame.pack();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
input.addTextListener(new TextListener(){
final BigDecimal factor = new BigDecimal("6.9");
public void textValueChanged(TextEvent e){
if(input.getText().trim().isEmpty()) {
output.setText("");
return;
}
try{
output.setText(new BigDecimal(input.getText()).multiply(factor).toString());
} catch (NumberFormatException xe){
input.setText("");
}
}
});
final Label from = new Label("From $:");
final Label to = new Label("To ¥:");
final TextField input = new TextField(10);
final TextField output = new TextField(10);
frame.setLayout(new GridLayout(4,1,5,5));
frame.add(from);
frame.add(input);
frame.add(to);
frame.add(output);
frame.pack();
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
input.addTextListener(new TextListener(){
final BigDecimal factor = new BigDecimal("6.9");
public void textValueChanged(TextEvent e){
if(input.getText().trim().isEmpty()) {
output.setText("");
return;
}
try{
output.setText(new BigDecimal(input.getText()).multiply(factor).toString());
} catch (NumberFormatException xe){
input.setText("");
}
}
});
展开全部
this.addActionListener(new TFListener());这一句根本就不同,不知道楼主那儿搞来的代码;text.settext(r)也不知道啥子情况
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用text.settext(r):定义r 为private 方法调用它(所以方法公用private属性)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
rtghdfhwshgdgdf
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询