《程序语言综合课程设计》实验报告 - 图文(8)

2019-08-01 23:36

计算机2011级 程序语言综合课程设计

centerInLeft.add(exp);

panelRight.setLayout(new BorderLayout());

panelRight.add(showComputerProcess,BorderLayout.NORTH); saveButton=new JButton(\保存\ copyButton=new JButton(\复制\ clearButton=new JButton(\清除\

saveButton.setToolTipText(\保存计算过程到文件\ copyButton.setToolTipText(\复制选中的计算过程\ clearButton.setToolTipText(\清除计算过程\ saveButton.addActionListener(this); copyButton.addActionListener(this); clearButton.addActionListener(this); panelRight.add(new

JScrollPane(saveComputerProcess),BorderLayout.CENTER); JPanel southInPanelRight=new JPanel(); southInPanelRight.add(saveButton); southInPanelRight.add(copyButton); southInPanelRight.add(clearButton);

panelRight.add(southInPanelRight,BorderLayout.SOUTH); JSplitPane split=new JSplitPane

(JSplitPane.HORIZONTAL_SPLIT,panelLeft,panelRight); add(split,BorderLayout.CENTER);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true);

setBounds(100,50,528,258); validate(); }

public void actionPerformed(ActionEvent e){

if(e.getSource()==about)

new Help();

int i=JOptionPane.showConfirmDialog(this, \终止当前程序运行?\ if (i==JOptionPane.YES_OPTION)

System.exit(0);

if(e.getSource()==exit){

33

计算机2011级 程序语言综合课程设计

}

if(e.getSource()==copyButton) saveComputerProcess.copy(); if(e.getSource()==clearButton) saveComputerProcess.setText(null); if(e.getSource()==saveButton){

JFileChooser chooser=new JFileChooser(); int state=chooser.showSaveDialog(null); File file=chooser.getSelectedFile();

if(file!=null&&state==JFileChooser.APPROVE_OPTION){ try{ String content=saveComputerProcess.getText(); StringReader read=new StringReader(content); BufferedReader in= new BufferedReader(read); FileWriter outOne=new FileWriter(file);

BufferedWriter out= new BufferedWriter(outOne); String str=null;

while((str=in.readLine())!=null){ out.write(str); out.newLine(); } in.close(); out.close(); }

catch(IOException e1){} } } }

public static void main(String args[]){ new CalculatorWindow(); } }

(2) HandleSin类

import java.util.LinkedList;

34

计算机2011级 程序语言综合课程设计

import javax.swing.*;

import java.awt.event.*;

public class HandleSin implements ActionListener{

LinkedList list;

JTextField resultShow,showComputerProcess;

JTextArea saveComputerProcess;

HandleSin(LinkedList list,JTextField t1,JTextField t2,

JTextArea t3){

this.list=list;

resultShow=t1;

showComputerProcess=t2;

saveComputerProcess=t3;

}

public void actionPerformed(ActionEvent e){

if(list.size()==1||list.size()==2){

String numOne=list.getFirst();

35

计算机2011级 程序语言综合课程设计

try{ double x=Double.parseDouble(numOne);

double result=Math.sin(x);

String str=String.valueOf(result);

list.set(0,str);

resultShow.setText(str);

String proccess=\

showComputerProcess.setText(proccess);

saveComputerProcess.append(\

if(list.size()==2)

list.removeLast(); //移掉运算符号

}

catch(Exception ee){}

}

else if(list.size()==3){

String numTwo=list.getLast();

try{ double x=Double.parseDouble(numTwo);

36

计算机2011级 程序语言综合课程设计

double result=Math.sin(x);

String str=String.valueOf(result);

list.set(0,str);

resultShow.setText(str);

}

}

}

String proccess=\

showComputerProcess.setText(proccess);

saveComputerProcess.append(\

list.removeLast(); //移掉第2个运算数

list.removeLast(); //移掉运算符号

}

catch(Exception ee){}

37


《程序语言综合课程设计》实验报告 - 图文(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:“坚守”作文讲评打印版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: