SWT计算器(加强版)汇率器
下面是的代,没有背景,大家可以自己添加,可以其他功能。实实实实实实实实实实实实实实实实实实实实实实实实实实实实实实
package lpdswt1;
import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.swt.widgets.Combo;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.List;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class ssss {
protected static Shell shell;private static List list;//容器 list框
private static Text importText1,importText2,fruitText;//实入框1,入框实实实2,果框实实实private static Combo algorithmCombo;//下拉框,运算,
private static Button btnCheckButton,btnCheckButton_1,btnCheckButton_2;//分实
+0.1,0.01,0.001
private static Button btnRadioButton,button_1;//实实实实实实实正数,数,
private static Button
memoryButton,resultButton1,resultButton2,deleteButton,countButton;//分是,果实实实实实实实1,实
果2,除,算实实实实实
private static Button keepButton, fetchButton;//存档和取按,实实实实实private static ArrayList la = new ArrayList();//一个新的容器private static String s;//实实量,用来做比
private static Double output,input1,input2;//实量,用来运算
private static Button openButton;//打新窗口的按实实实实实实实
protected static Shell shell1;//从原有窗口中打的一个新窗口,而且实实实实实实实实实实实
实实实实实实实实实实实实实实实实实实,此窗口不的情况下,无法原窗口行控制
private static Display display = Display.getDefault();
private static Text fruitText1,yearText,rateText;//分是果框,年数,利率框实实实实实实实实实实实实private static Button byeButton,equalButton;//运算符和等号
public static void main(String[] args) {
try {
ssss window = new ssss();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
while (!shell1.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
//个个量实实
protected void createContents() {
shell =new Shell();
shell.setSize(450, 300);
shell.setText("存档算器实实实");
importText1 = new Text(shell, SWT.BORDER);
importText1.setBounds(0, 33, 73, 25);importText1.setTextLimit(5);
Label label = new Label(shell, SWT.NONE);label.setBounds(0, 10, 61, 17);
label.setText("实入1");
algorithmCombo = new Combo(shell, SWT.NONE);algorithmCombo.setBounds(79, 33, 73, 23);algorithmCombo.add("加");
algorithmCombo.add("减");
algorithmCombo.add("乘");
algorithmCombo.add("除以");
importText2 = new Text(shell, SWT.BORDER);importText2.setBounds(165, 33, 73, 25);importText2.setTextLimit(5);
Label lblNewLabel = new Label(shell, SWT.NONE);lblNewLabel.setBounds(166, 10, 54, 17);lblNewLabel.setText("实入2");
countButton = new Button(shell, SWT.NONE);countButton.setBounds(255, 33, 80, 27);countButton.setText("实算");
countButton.addSelectionListener(new CountButtonListener());//触事件实实实
btnCheckButton = new Button(shell, SWT.CHECK);btnCheckButton.setBounds(0, 62, 47, 17);btnCheckButton.setText("+0.1");
btnCheckButton_1 = new Button(shell, SWT.CHECK);btnCheckButton_1.setBounds(0, 81, 54, 17);btnCheckButton_1.setText("+0.01");
btnCheckButton_2 = new Button(shell, SWT.CHECK);btnCheckButton_2.setBounds(0, 100, 61, 17);btnCheckButton_2.setText("+0.001");btnRadioButton = new Button(shell, SWT.RADIO);btnRadioButton.setBounds(77, 62, 30, 17);btnRadioButton.setText("+");
button_1 = new Button(shell, SWT.RADIO);button_1.setBounds(77, 81, 30, 17);button_1.setText("-");
Label label_3= new Label(shell, SWT.NONE);label_3.setBounds(338, 10, 61, 17);label_3.setText("实果");
fruitText = new Text(shell, SWT.BORDER);fruitText.setBounds(341, 33, 83, 25);list = new List(shell, SWT.MULTI | SWT.V_SCROLL|SWT.NONE);
list.setBounds(41, 174, 91, 88);
resultButton1 = new Button(shell, SWT.NONE);
resultButton1.setBounds(0, 123, 47, 27);
resultButton1.setText("1实果");
resultButton1.addSelectionListener(new ResultButtonListener_1());//出事实实
件,下同
resultButton2 = new Button(shell, SWT.NONE);
resultButton2.setBounds(53, 123, 47, 27);
resultButton2.setText("2实果");
resultButton2.addSelectionListener(new ResultButtonListener_2());deleteButton = new Button(shell, SWT.NONE);
deleteButton.setBounds(106, 123, 46, 27);
deleteButton.setText("实除");
deleteButton.addSelectionListener(new DeleteButtonListener());memoryButton= new Button(shell, SWT.NONE);
memoryButton.setBounds(338, 62, 86, 32);
memoryButton.setText("实实");
memoryButton.addSelectionListener(new MemoryButtonListener());keepButton = new Button(shell, SWT.NONE);
keepButton.setBounds(163, 123, 57, 27);
keepButton.setText("保存");
keepButton.addSelectionListener(new KeepButtonListener());fetchButton = new Button(shell, SWT.NONE);
fetchButton.setBounds(226, 123, 54, 27);
fetchButton.setText("实取");
fetchButton.addSelectionListener(new FetchButtonListener());openButton=new Button(shell,SWT.NONE);
openButton.setBounds(300, 200, 84, 27);
openButton.setText("打窗口实实实B");
Label lblNewLabel_1 = new Label(shell, SWT.NONE);lblNewLabel_1.setBounds(41, 156, 61, 17);
lblNewLabel_1.setText("\u8BB0\u5FC6\u6846list");openButton.addSelectionListener(new OpenButtonListener());
}
//一个算法事件
public static class CountButtonListener extends SelectionAdapter {public void widgetSelected(SelectionEvent e){
input1=Double.parseDouble(importText1.getText());
input2=Double.parseDouble(importText2.getText());
s=new
String(algorithmCombo.getItem(algorithmCombo.getSelectionIndex()));
if(s.equals("加")){
output=input1+input2;
}else if(s.equals("减")){
output=input1-input2;
}else if(s.equals("乘")){
output=input1*input2;
}else if(s.equals("除以")){
output=input1/input2;
}
if(btnCheckButton.getSelection()){
output=output+0.1;
}else if(btnCheckButton_1.getSelection()){
output=output+0.01;
}else if(btnCheckButton_2.getSelection()){
output=output+0.001;
}
if(btnRadioButton.getSelection()){
output=+(output);
}else if(button_1.getSelection()){
output=-(output);
}
fruitText.setText(""+output);
}
}
//一个的事件实实实实实
public static class MemoryButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
String memory= fruitText.getText();
la.add(memory);
list.add(memory);
int i = list.getItemCount();
list.setSelection(i-1);
/*String input1=importText1.getText();
String input2=importText2.getText();
StringBuffer my1=new StringBuffer();
my1.append(input1);
my1.append(s);
my1.append(input2);
my1.append("=");
my1.append(memory);
la.add(my1.toString());
int i=list.getItemCount();
list.setSelection(i-1);
list.add((String)la.get(i));*/
}
}
//一个除事件实实实实
public static class DeleteButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
int db = list.getFocusIndex();//实中一个焦掉
la.remove(db);
list.remove(db);
}
}
//一个果到入框实实实实实实1的事件
public static class ResultButtonListener_1 extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
String[] result = list.getSelection();//实实实一个焦点的
importText1.setText(result[0]);
}
}
//一个果到入框实实实实实实2的事件
public static class ResultButtonListener_2 extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
String[] result_1= list.getSelection();
importText2.setText(result_1[0]);
}
}
//一个存档事件
public static class KeepButtonListener extends SelectionAdapter {
BufferedWriter bw = null;
public void widgetSelected(SelectionEvent e){
try {
bw = new BufferedWriter(new
FileWriter("f:\\_lipeidong\\java.txt",true));
String[] result_2 = list.getSelection();
for(int i = 0;i < result_2.length;i++){
bw.write(result_2[i]);
bw.write("\n");
}
bw.close();
}catch (IOException e1) {
e1.printStackTrace();
}
}
}
//一个取存档的事件实实实实实实实
public static class FetchButtonListener extends SelectionAdapter {
private BufferedReader br;
public void widgetSelected(SelectionEvent e){
try {
FileReader fr=new FileReader("f:\\_lipeidong\\java.txt");
br = new BufferedReader (fr);
String test;
while ((test=br.readLine())!=null) {
la.add(test);
list.add(test);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
//从原有窗口打一个新的窗口实实实实实实实
public static class OpenButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
shell1 =new Shell(getParent(),SWT.DIALOG_TRIM | SWT.MIN |
SWT.MAX|SWT.APPLICATION_MODAL);
shell1.setSize(300, 200);
shell1.setText("年利率算器器实实实实");
shell1.open();
shell1.layout();
byeButton = new Button(shell1, SWT.NONE);byeButton.setBounds(75, 32, 26, 21);byeButton.setText("*");
equalButton = new Button(shell1, SWT.NONE);equalButton.setBounds(176, 34, 34, 21);equalButton.setText("=");
equalButton.addSelectionListener(new fruitTextListener());
rateText = new Text(shell1, SWT.BORDER);rateText.setBounds(10, 34, 59, 21);
//rateText.addSelectionListener(new RateTextListener());
yearText = new Text(shell1, SWT.BORDER);yearText.setBounds(108, 34, 55, 21);//yearText.addSelectionListener(new YearTextListener());
fruitText1 = new Text(shell1, SWT.BORDER);fruitText1.setBounds(216, 34, 55, 21);Label lblNewLabe2 = new Label(shell1, SWT.NONE);lblNewLabe2.setBounds(10, 13, 55, 15);lblNewLabe2.setText("年利率");
Label labe2 = new Label(shell1, SWT.NONE);labe2.setBounds(108, 13, 55, 15);
labe2.setText("年份");
Label label_1 = new Label(shell1, SWT.NONE);label_1.setBounds(216, 13, 55, 15);
label_1.setText("实果");
}
private Display getParent() {
// TODO 自生成的方法存根实实实实实实实实
return null;
}
}
/*public static class RateTextListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){double int1,int2;
int1=Double.parseDouble(rateText.getText());int2=Double.parseDouble(yearText.getText());
String str = rateText.getText();
if(Integer.parseInt(str)<1&Integer.parseInt(str)>0){
fruitText1.setText(""+(int1*int2));
}else {
System.out.print("no");
}
}
}*/
public static class fruitTextListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e){
double int1,int2;String str = rateText.getText();
int1=Double.parseDouble(rateText.getText());
int2=Double.parseDouble(yearText.getText());
if(Double.parseDouble(str)<1&&Double.parseDouble(str)>0){
fruitText1.setText(""+Math.pow(int1,int2));
}else {
MessageDialog.openInformation(shell, "", "年利率实实
入大于0小于1的数");
}
}
}
}