//我简单编了一个,看看可以吗??
//不行我再加强,发短消息给我import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class WeightConversionApp
{
public static void main(String[] args)
{
WeightConversionFrame frame=new WeightConversionFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class WeightConversionFrame extends JFrame
{
public WeightConversionFrame()
{
setTitle("Weight Conversion");
setSize(500,200); pounds=new JTextField(20);
kilograms=new JTextField(20); JButton pTok=new JButton("pounds to kilograms");
JButton kTop=new JButton("kilograms to pounds");
JButton exit=new JButton("exit"); pTok.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
double dPounds=0.0;
String strPounds=pounds.getText(); if(strPounds.length()==0)
{
JOptionPane.showMessageDialog(
WeightConversionFrame.this,
"Please input the 'pounds' value");
pounds.requestFocus();
return;
}
try
{
dPounds=Double.parseDouble(strPounds);
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(
WeightConversionFrame.this,
"the pounds valude format error,please edit it");
pounds.requestFocus();
pounds.selectAll();
return;
} double dKilograms=dPounds/2.2;
kilograms.setText(String.valueOf(dKilograms));
} });
kTop.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
double dKilograms=0.0;
String strKilograms=kilograms.getText(); if(strKilograms.length()==0)
{
JOptionPane.showMessageDialog(
WeightConversionFrame.this,
"Please input the 'kilograms' value");
kilograms.requestFocus();
return;
}
try
{
dKilograms=Double.parseDouble(strKilograms);
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(
WeightConversionFrame.this,
"the kilograms valude format error,please edit it");
kilograms.requestFocus();
kilograms.selectAll();
return;
} double dPounds=dKilograms*2.2;
pounds.setText(String.valueOf(dPounds));
} }); exit.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});

JPanel panelPounds=new JPanel(); panelPounds.add(new JLabel("Pounds   ",SwingConstants.LEFT));
panelPounds.add(pounds); JPanel panelKilograms=new JPanel();
panelKilograms.add(new JLabel("Kilograms",SwingConstants.LEFT));
panelKilograms.add(kilograms); JPanel panelButton=new JPanel();
panelButton.add(pTok);
panelButton.add(kTop);
panelButton.add(exit); Container contentPane=getContentPane();
contentPane.setLayout(new GridLayout(3,1));
contentPane.add(panelPounds);
contentPane.add(panelKilograms);
contentPane.add(panelButton);
}

JTextField pounds=null;
JTextField kilograms=null;
}