学习笔记_JFame事件处理的三种方法(1)直接实现法
2014-07-31 19:40
639 查看
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextField; import cc12.ClientFFFFF; public class FileSend extends JFrame{ static File file = null; public FileSend(){ //FlowLayout layout=new FlowLayout(); //this.setLayout(layout); this.setLayout(null); JButton button=new JButton("选择文件"); button.setBounds(30, 30, 100, 50); final JTextField fileName=new JTextField(); //JComboBox jcb=new JComboBox(new String[]{"1.上传文件","2.上传对象","3.向服务器问好"}); //jcb.setEditable(true); //this.add(jcb); this.add(new JButton("按钮",new ImageIcon("d:/eclipse.jpg"))); fileName.setBounds(200,30,300,50); this.add(fileName); this.add(button); JButton button1=new JButton("发送文件文件"); button1.setBounds(200, 300, 100, 50); this.add(button1); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc=new JFileChooser(); jfc.showOpenDialog(FileSend.this); file=jfc.getSelectedFile(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); String fileNameStr=file.getAbsolutePath(); JOptionPane.showMessageDialog(FileSend.this, fileNameStr); fileName.setText(fileNameStr); } }); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String fileSrc=file.getAbsolutePath(); ClientFFFFF sc = new ClientFFFFF(); sc.connectSocketServer(1234); sc.sendFile(fileSrc); } }); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /*JFileChooser jfc=new JFileChooser(); jfc.setBounds(30, 100, 400, 400); this.add(jfc);*/ this.setSize(600, 600); this.setVisible(true); } public static void main(String[] args) { FileSend sender=new FileSend(); } }
相关文章推荐
- 学习笔记_JFame事件处理的三种方法(3)类直接实现接口法
- 学习笔记_JFame事件处理的三种方法(2)内部类实现
- EJB3.0学习笔记---多接口的时,实现类处理方法:
- 三种方法实现网页下载-(慕课网学习笔记)
- 黑马程序员—C学习笔记—三种方法实现两数交换
- Dynamic CRM 2013学习笔记(二十)字段改变事件的二种实现方法
- Silverlight学习笔记(七)-----Silverlight事件处理之鼠标事件实现简单拖拽
- Android开发学习笔记:Button事件实现方法的总结
- Android开发学习笔记:Button事件实现方法的总结
- CSS实现圆角的三种方法以下直接给出代码:
- 学习Altas 笔记[js调用重载的方法出错,如何处理]
- Java Swing 中三种事件处理方法比较
- wss3 sdk学习笔记四:事件处理
- 一个无聊男人的疯狂《数据结构与算法分析-C++描述》学习笔记 用C++/lua/python/bash的四重实现(7)习题2.8 随机数组的三种生成算法
- Ext javascript建立超链接,进行事件处理的实现方法
- Silverlight学习笔记一:DataGrid如何处理鼠标的滚轮事件
- 键盘 事件处理 -Java学习笔记(37)
- 事件处理程序实现的另一种方法:浏览器的事件监听机制实现“1事件对应n事件处理程序”(Javascript)
- Java Swing 中三种事件处理方法之比较
- 孙鑫VC学习笔记:第十六讲 利用事件对象实现线程间的同步