/*
* To
change this license header, choose License Headers in Project Properties.
* To
change this template file, choose Tools | Templates
*
and open the template in the editor.
*/
package lianxi5;
import com.sun.prism.j2d.J2DPipeline;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/**
*
*
@author user
*/
public class Lianxi5 extends JFrame{
JPanel p;
JLabel l;
JComboBox x;
JComboBox y;
JButton btSunmit;
JTextArea A;
JTextArea B;
JTextArea C;
public void init()
{
p=new JPanel();
btSunmit=new JButton("=");
A=new JTextArea(1,3);
B=new JTextArea(1,3);
C=new JTextArea(“请输入要换算的货币数目”);
x=new JComboBox();
x.addItem(“人民币”);
x.addItem(“美元”);
x.addItem(“日元”);
A.setEditable(true);
B.setEditable(true);
C.setEditable(false);
y=new JComboBox();
y.addItem(“人民币”);
y.addItem(“美元”);
y.addItem(“日元”);
p.add©;
p.add(A);
p.add(x);
p.add(btSunmit);
p.add(B);
p.add(y);
p.setBorder(BorderFactory.createTitledBorder(“换算”));
p.setForeground(Color.red);
A.setBorder(BorderFactory.createBevelBorder(WIDTH));
B.setBorder(BorderFactory.createBevelBorder(WIDTH));
this.add§;
this.setLayout(new FlowLayout());
this.setTitle(“货币换算”);
this.setSize(500,300);
this.setLocation(100,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setForeground(Color.BLACK);
btSunmit.addActionListener(new M());
}
private class M implements ActionListener{
public void actionPerformed(ActionEvent e){
int
n=Integer.parseInt(A.getText());
if(x.getSelectedIndex()==0)
{
if
(y.getSelectedIndex()==0)
{B.setText(Integer.toString(n));}
else if
(y.getSelectedIndex()==1)
{B.setText(Integer.toString(n/8));}
else if
(y.getSelectedIndex()==2)
{B.setText(Integer.toString(n*100));}
}
else
if(x.getSelectedIndex()==1)
{
n=n*8;
if
(y.getSelectedIndex()==0)
{B.setText(Integer.toString(n));}
else if
(y.getSelectedIndex()==1)
{B.setText(Integer.toString(n/8));}
else if (y.getSelectedIndex()==2)
{B.setText(Integer.toString(n*100));
}
}
else if(x.getSelectedIndex() ==
2)
{
n=n/100;
if (y.getSelectedIndex()==0)
{B.setText(Integer.toString(n));}
else if
(y.getSelectedIndex()==1)
{B.setText(Integer.toString(n/8));}
else if
(y.getSelectedIndex()==2)
{B.setText(Integer.toString(n*100));}
}
}
}
/**
- @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
lianxi5.Lianxi5 test =new Lianxi5();
test.init();
}
}