教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

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

来源:网络收集 时间:2026-02-07
导读: 输出结果 shop.addBooks(); //购物车中加东西 HashMap book4=(HashMap)shop.getBook3(); shop.getSum(book4); //购物车算总价 } } 《JAVA程序设计》实验报告8 姓名 杨仕琴 学号 54121022 日期 10.13 实验题目 packa

输出结果 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));

…… 此处隐藏:489字,全部文档内容请下载后查看。喜欢就下载吧 ……
《JAVA程序设计》实验报告(DOC)(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521199.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)