帅的实验8

/*

* 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();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会coding的coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值