《JAVA程序设计》实验报告(DOC)(8)

2019-08-31 09:18

输出结果 shop.addBooks(); //购物车中加东西 HashMap book4=(HashMap)shop.getBook3(); shop.getSum(book4); //购物车算总价 } } 《JAVA程序设计》实验报告8

姓名 杨仕琴 学号 54121022 日期 10.13 实验题目 package unit8; 程序初稿 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class ddd extends JFrame implements ActionListener { JTextArea txtMessage; JButton btnRead, btnWrite; public ddd() { super(\文本读写\txtMessage = new JTextArea(15, 30); btnRead = new JButton(\读取\btnWrite = new JButton(\写入\this.setLayout(new FlowLayout()); this.add(new JLabel(\文件内容:\this.add(txtMessage); this.add(btnRead); this.add(btnWrite); btnRead.addActionListener(this); btnWrite.addActionListener(this); this.setSize(400, 400); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public static void main(String[] args) { new ddd(); } public void actionPerformed(ActionEvent e) { JButton btn = (JButton)e.getSource(); String fileName = \if(btn.getText().equals(\读取\try{ InputStream is = new FileInputStream(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer buffer = new StringBuffer(); while((line = br.readLine()) != null){ buffer.append(line + \} txtMessage.setText(buffer.toString()); br.close(); is.close(); } else if(btn.getText().equals(\写入\try{ String msg = txtMessage.getText(); OutputStream os = new FileOutputStream(fileName); PrintStream ps = new PrintStream(os); ps.print(msg); ps.close(); os.close(); } } } } 所遇问题 及 文件读写的类太多,查API查很久 解决办法 package unit8; 调试后的import java.awt.*; 程序代码 import java.awt.event.*; import javax.swing.*; import java.io.*; public class ddd extends JFrame implements ActionListener { JTextArea txtMessage; JButton btnRead, btnWrite; public ddd() { super(\文本读写\txtMessage = new JTextArea(15, 30); btnRead = new JButton(\读取\btnWrite = new JButton(\写入\this.setLayout(new FlowLayout()); this.add(new JLabel(\文件内容:\this.add(txtMessage); this.add(btnRead); this.add(btnWrite); btnRead.addActionListener(this); btnWrite.addActionListener(this); this.setSize(400, 400); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public static void main(String[] args) { new ddd(); } @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton)e.getSource(); String fileName = \if(btn.getText().equals(\读取\try{ InputStream is = new FileInputStream(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(is));


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

下一篇:自动控制原理课后习题答案

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

马上注册会员

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