9.Java图形用户界面设计说明书.ppt

  1. 1、本文档共142页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.filechooser.*; public class JFileChooserDemo extends JFrame { public JFileChooserDemo() { super(使用JFileChooser); final JTextArea ta = new JTextArea(5,20); ta.setMargin(new Insets(5,5,5,5)); ta.setEditable(false); JScrollPane sp = new JScrollPane(ta); final JFileChooser fc = new JFileChooser(); JButton openBtn = new JButton(打开文件...); openBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { int returnVal = fc.showOpenDialog( JFileChooserDemo.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); ta.append(打开: + file.getName() + .\n); } else ta.append(取消打开命令.\n); } }); JButton saveBtn = new JButton(保存文件...); saveBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ int returnVal = fc.showSaveDialog( JFileChooserDemo.this); if (returnVal == JFileChooser.APPROVE_OPTION){ File file = fc.getSelectedFile(); ta.append(Saving: + file.getName() + .\n); } else ta.append(取消保存命令。\n); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(openBtn); buttonPanel.add(saveBtn); openBtn.setNextFocusableComponent(saveBtn); saveBtn.setNextFocusableComponent(openBtn); Container c = getContentPane(); c.add(buttonPanel, BorderLayout.NORTH); c.add(sp, BorderLayout.CENTER); } public static void main(String[] args) { JFrame frame = new JFileChooserDemo(); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } 程序运行的开始界面如下图左,选择“打开文件”按钮后,即出现下图右的打开文件对话框,选择文件后将选择文件名显示到文本区域中。选择“保存文件”按钮,将出现文件保存对话框。 例9.23的运行界面。 9.4 鼠标和键盘事件 在GUI程序中,通常使用鼠标来进行人机交互操作。鼠标的移动、单击、双击等都会引发鼠标事件。为输入数据、操作命令等,也使用键盘。键盘的按下,释放也会引发键盘事件。下面简单介绍AWT的鼠标和键盘事件的处理。 9.4.1 鼠标事件 处理鼠标事件的程序要实现在java.awt.event包中定义的两个接口MouseListener和MouseMotionListener,在这两个接口中定义了未实现的鼠标事件处理方法。 接口MouseListener中的方法为: public void mousePressed(MouseEvent e)处理按下鼠标左

文档评论(0)

smdh + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档