java编程问题~~~急
来源:百度知道 编辑:UC知道 时间:2024/05/27 05:17:11
我想问一下2楼的,你的程序单独运行是对的,可我把你的text.setText((Double.parseDouble(text.getText()))/1000.000+"");这个语句搬到我的程序中,就出现无法将 javax.swing.text.JTextComponent 中的 setText(java.lang.String) 应用于 (double)
textFieldSet1.setText((Double.parseDouble( textFieldSet1.getText()))/1000.000);
帮忙看下
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingTest extends JFrame implements ActionListener
{
JPanel jp=new JPanel();
JComboBox box=new JComboBox(new String[]{"Hz","KHz"});
JTextField text=new JTextField(10);
public SwingTest()
{
jp.add(text);
jp.add(box);
text.setText(100000.000+"");
text.setEditable(false);
box.addActionListener(this);
this.add(jp);
this.setVisible(true);
this.setBounds(100,100,300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
String s=(String)box.getSelectedItem();
if(s.equals("KHz"))
{
text.setText((Double.parseDouble(text.getText()))/1000.000+"");
}
}
public static void main(String[] args)
{
new SwingTest();
}