import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.Timer;
public class Cm implements ActionListener,ItemListener
{
JFrame f;
Timer timer; JButton b1;
JTextArea in;
JTextField out;
double n;
double mj;
JLabel top,top1,top2;
JComboBox combo1;
public void draw()
{ f=new JFrame("米重计算"); b1=new JButton("确定");
in=new JTextArea();
out=new JTextField();
top1=new JLabel("面积");
top2=new JLabel("米重"); String[] s = {"铝材","钢材"}; combo1 = new JComboBox(s);
combo1.addItem("");
combo1.setBorder(BorderFactory.createTitledBorder("型材"));
//按键
b1.setSize(80,20);
b1.setLocation(60,130);
//文本框
in.setSize(100,20);
in.setLocation(55,70); out.setSize(100,20);
out.setLocation(55,100); top1.setSize(100,30);
top1.setLocation(10,67); top2.setSize(100,30);
top2.setLocation(10,97);
// combo1.setSize(150,50);
combo1.setLocation(25,10);
f.setLayout(null);
f.add(b1);
f.add(in);
f.add(out);
f.add(top1);
f.add(top2); f.add(combo1);
b1.addActionListener(this);
b1.setBorder(BorderFactory.createLineBorder(Color.blue,3));
combo1.addActionListener(new ActionListener(this));
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200,200);
f.setLocation(150,150);
f.show(); } /*public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
n = Long.parseLong(in.getText()); 铝材面积();
}*/
public void itemStateChanged(ItemEvent e)//针对JComboBox
{
if(combo1.getSelectedIndex()==0) 铝材面积();
if(combo1.getSelectedIndex()==1) 钢材面积();
}
public void actionPerformed(ActionEvent e)//针对JButton
{
if(e.getSource()==button1) n = Long.parseLong(in.getText()); //方法没写我想通过combo1通给方法参数,通过button1获取JTextArea in的值 并进行计算
} /*
*hwh2zyq 我编译通不过*/
//下面是方法 public void 铝材面积(){
double x=2.75,y=1000;
mj=x/y*n;
BigDecimal bd = new BigDecimal(mj);
BigDecimal returnValue = bd.divide(new BigDecimal(1.0), 2, BigDecimal.ROUND_HALF_UP);
out.setText(returnValue +" kg/m");
}
public void 钢材面积(){
double x=7.85,y=1000;
mj=x/y*n;
out.setText(String.valueOf(mj)+" kg/m(钢材)");
}
public static void main(String[] args)
{ Cm s= new Cm();
s.draw();
} }
//方法没写我想通过combo1通给方法参数,通过button1获取JTextArea in的值 并进行计算
要编译通的过,谁可以帮我改改,谢谢!
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.Timer;
public class Cm implements ActionListener,ItemListener
{
JFrame f;
Timer timer; JButton b1;
JTextArea in;
JTextField out;
double n;
double mj;
JLabel top,top1,top2;
JComboBox combo1;
public void draw()
{ f=new JFrame("米重计算"); b1=new JButton("确定");
in=new JTextArea();
out=new JTextField();
top1=new JLabel("面积");
top2=new JLabel("米重"); String[] s = {"铝材","钢材"}; combo1 = new JComboBox(s);
combo1.addItem("");
combo1.setBorder(BorderFactory.createTitledBorder("型材"));
//按键
b1.setSize(80,20);
b1.setLocation(60,130);
//文本框
in.setSize(100,20);
in.setLocation(55,70); out.setSize(100,20);
out.setLocation(55,100); top1.setSize(100,30);
top1.setLocation(10,67); top2.setSize(100,30);
top2.setLocation(10,97);
// combo1.setSize(150,50);
combo1.setLocation(25,10);
f.setLayout(null);
f.add(b1);
f.add(in);
f.add(out);
f.add(top1);
f.add(top2); f.add(combo1);
b1.addActionListener(this);
b1.setBorder(BorderFactory.createLineBorder(Color.blue,3));
combo1.addActionListener(new ActionListener(this));
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200,200);
f.setLocation(150,150);
f.show(); } /*public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
n = Long.parseLong(in.getText()); 铝材面积();
}*/
public void itemStateChanged(ItemEvent e)//针对JComboBox
{
if(combo1.getSelectedIndex()==0) 铝材面积();
if(combo1.getSelectedIndex()==1) 钢材面积();
}
public void actionPerformed(ActionEvent e)//针对JButton
{
if(e.getSource()==button1) n = Long.parseLong(in.getText()); //方法没写我想通过combo1通给方法参数,通过button1获取JTextArea in的值 并进行计算
} /*
*hwh2zyq 我编译通不过*/
//下面是方法 public void 铝材面积(){
double x=2.75,y=1000;
mj=x/y*n;
BigDecimal bd = new BigDecimal(mj);
BigDecimal returnValue = bd.divide(new BigDecimal(1.0), 2, BigDecimal.ROUND_HALF_UP);
out.setText(returnValue +" kg/m");
}
public void 钢材面积(){
double x=7.85,y=1000;
mj=x/y*n;
out.setText(String.valueOf(mj)+" kg/m(钢材)");
}
public static void main(String[] args)
{ Cm s= new Cm();
s.draw();
} }
//方法没写我想通过combo1通给方法参数,通过button1获取JTextArea in的值 并进行计算
要编译通的过,谁可以帮我改改,谢谢!
楼主【BAIYMT】截止到2008-07-25 15:37:31的历史汇总数据(不包括此帖):
发帖的总数量:3 发帖的总分数:40 每贴平均分数:13
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:2 结贴的总分数:20
无满意结贴数:1 无满意结贴分:20
未结的帖子数:1 未结的总分数:20
结贴的百分比:66.67 % 结分的百分比:50.00 %
无满意结贴率:50.00 % 无满意结分率:100.00%
楼主加油