java温度显示代码设计 java温度换算( 四 )


if(e.getSource()==drCircle)//画圆
if(e.getSource()==drRect)//画矩形
if(e.getSource()==colchooser)//调色板
{
Color newColor = JColorChooser.showDialog(this,"调色板",c);
c = newColor;
}
if(e.getSource()==openPic)//打开图画
{
openPicture.setVisible(true);
if(openPicture.getFile()!=null)
{
int tempflag;
tempflag = toolFlag;
toolFlag = 2 ;
repaint();
try{
paintInfo.removeAllElements();
File filein = new File(openPicture.getDirectory(),openPicture.getFile());
picIn = new FileInputStream(filein);
VIn = new ObjectInputStream(picIn);
paintInfo = (Vector)VIn.readObject();
VIn.close();
repaint();
toolFlag = tempflag;
}
catch(ClassNotFoundException IOe2)
{
repaint();
toolFlag = tempflag;
System.out.println("can not read object");
}
catch(IOException IOe)
{
repaint();
toolFlag = tempflag;
System.out.println("can not read file");
}
}
}
if(e.getSource()==savePic)//保存图画
{
savePicture.setVisible(true);
try{
File fileout = new File(savePicture.getDirectory(),savePicture.getFile());
picOut = new FileOutputStream(fileout);
VOut = new ObjectOutputStream(picOut);
VOut.writeObject(paintInfo);
VOut.close();
}
catch(IOException IOe)
{
System.out.println("can not write object");
}
}
}
}//end paintboard
public class pb
{
public static void main(String args[])
}
________________________________________-
30分给你程序了,你真是 。。。
我以前别人要源码的我100分才给的,
我都没用过awt,swing,里面的函数我都看不懂怎么话流程,你既然java是玩GUI的,流程图肯定自己要学着画,不然你怎么提高,我j2ee开发文档的流程图也都自己画的,
你觉得我这个给的不好你就把问题关闭了吧
JAVA题:编写一个能够转换华氏温度和摄氏温度的程序 。在“摄氏温度”文本域输入一个值并点击华氏按钮(两import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class TemperatureFrame extends JFrame implements ActionListener {
private JButton transformFButton = new JButton("摄氏转华氏");
private JButton transformCButton = new JButton("华氏转摄氏");
private JTextField fTextField = new JTextField();
private JTextField cTextField = new JTextField();
float c, f;
public TemperatureFrame() {
super("华氏温度摄氏温度转换");
try {
init();
} catch (Exception e) {
e.printStackTrace();
}
}
private void init() {
fTextField.setBounds(10, 30, 100, 25);
cTextField.setBounds(130, 30, 100, 25);
transformCButton.setBounds(10, 58, 100, 25);
transformFButton.setBounds(130, 58, 100, 25);
transformCButton.addActionListener(this);
transformFButton.addActionListener(this);
Container c = getContentPane();
c.add(fTextField);
c.add(cTextField);
c.add(transformCButton);
c.add(transformFButton);
c.setLayout(null);
this.setSize(250, 150);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new TemperatureFrame();
}
public void actionPerformed(ActionEvent e) {
//华氏温度F与摄氏度C
//F= C* 9/5 + 32
//C=(F-32)*5/9
if (e.getSource() == transformFButton) {
try {
c = Float.parseFloat(cTextField.getText());

推荐阅读