popupMenu_Delete = new JMenuItem(\删除(D)\, 'D'); p_zip =new JMenuItem(\添加到压缩文件\);
// ---------------向右键菜单添加菜单项和分隔符 popupMenu.addSeparator(); popupMenu.add(newfiles);
popupMenu.add(popupMenu_Copy); popupMenu.add(p_zip);
popupMenu.add(popupMenu_Delete); popupMenu.addSeparator();
// --------------------右键菜单注册事件 popupMenu_Copy.setActionCommand(\复制(C)\); popupMenu_Copy.addActionListener(this);
popupMenu_Delete.setActionCommand(\删除(D)\); popupMenu_Delete.addActionListener(this); newfiles.setActionCommand(\新建文件夹\); newfiles.addActionListener(this); p_zip.addActionListener(this); jtree.add(popupMenu);
///////////////////////////////////////////////////////////// menu = new PopupMenu();
newfload=new MenuItem(\新建文件夹\); newfile=new MenuItem(\新建文件\); b_open=new MenuItem(\打开\); b_copy=new MenuItem(\复制\);
b_Zip=new MenuItem(\添加到压缩文件\); b_del=new MenuItem(\删除\);
b_rename=new MenuItem(\重命名\); menu.addSeparator(); menu.add(b_open); menu.add(newfload); menu.add(newfile); menu.add(b_copy); menu.add(b_Zip); menu.add(b_rename); menu.add(b_del); menu.addSeparator();
b_open.addActionListener(this); newfload.addActionListener(this); b_copy.addActionListener(this); b_del.addActionListener(this); b_Zip.addActionListener(this);
b_rename.addActionListener(this); newfile.addActionListener(this); JPsub.add(menu);
////////////////////////////////////////////////////////////// //水平分割窗口,左scrollPane内放tree,右放JPsub用于显示文件 JSP=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(jtree),new JScrollPane(JPsub));
JSP.setDividerLocation (200);////////设置分隔条的位置。
JSP.setLastDividerLocation(200); /////// 将分隔条所处的最后位置设置为 newLastLocation。
getContentPane().add(JSP);
//背景色为白
JPsub.setBackground(Color.white); //////////////////////////////////////
/////////////////////////////////////////////时间///////////////////////
statusBar = new JToolBar();
shijian = new JLabel(\当前时间:\ + hour + \ + min + \ + second);
statusBar.addSeparator(); statusBar.add(shijian);
statusBar.setVisible(true);
container.add(statusBar, BorderLayout.SOUTH); statusBar.setVisible(true);
////////////////////////////////////////////// //给树添加展开监听器
jtree.addTreeExpansionListener(this); jtree.addTreeSelectionListener(this);
//设置树的外形 ,改变文件夹的图案 try {
UIManager.setLookAndFeel(\AndFeel\);
SwingUtilities.updateComponentTreeUI(this); }
catch (Exception ex) {}
jtree.setShowsRootHandles(true);
getContentPane().add(road,BorderLayout.NORTH); road.add(status,BorderLayout.WEST); ///西边....左边 Clock clock=new Clock();////线程 clock.start();
////////////////////////////////////////////////// f = new JFrame(\重命名\) ;
f.setSize(230,80) ; // 设置组件的大小
f.setBackground(Color.WHITE) ; // 将背景设置成白色 f.setLocation(300,200) ; // 设置组件的显示位置 renamest=new JTextField(); sure=new JButton(\确定\);
f.add(renamest,BorderLayout.CENTER); f.add(sure,BorderLayout.SOUTH); sure.addActionListener(this);
////////////////////////////////////////////////// ff = new JFrame(\压缩文件名\) ;
ff.setSize(230,80) ; // 设置组件的大小 ff.setBackground(Color.WHITE) ; // 将背景设置成白色 ff.setLocation(300,200) ; // 设置组件的显示位置 zipname=new JTextField(); ok=new JButton(\确定\);
ff.add(zipname,BorderLayout.CENTER); ff.add(ok,BorderLayout.SOUTH); ok.addActionListener(this); }
////////////实现复制,黏贴功能//////////////////////////// class MainFrame extends JFrame { /** * */
private static final long serialVersionUID = 1L;
public MainFrame() {
super(\);
setDefaultCloseOperation(HIDE_ON_CLOSE); setSize(500,260);
setLocation(300,200) ;
MainPanel pan = new MainPanel(); setContentPane(pan); setLayout(null); }
}
class MainPanel extends JPanel {
/** * */
private static final long serialVersionUID = 1L; JTextField txt;
JTextArea txtInFile; JTextArea txtOutFile; JFileChooser open; String strFilePath;
String strFilePathCopyTo; public MainPanel() {
JLabel lblIn = new JLabel(\源文件:\); lblIn.setBounds(30, 65, 50, 20); if(F_list.isSelectionEmpty())
txtInFile = new JTextArea(zhantie()); else
txtInFile = new JTextArea(zhantie()+F_list.getSelectedValue()); JScrollPane scrint = new JScrollPane(txtInFile) ; scrint.setBounds(80,65,265,40);
JButton btnSelect = new JButton(\选择文件或目录\); btnSelect.setBounds(350, 65, 120, 20);
open = new JFileChooser();/////////////////////
txtInFile = new JTextArea(zhantie()+F_list.getSelectedValue()); open.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); open.setCurrentDirectory(new File(zhantie())); btnSelect.addActionListener(new ActionListener() {
@SuppressWarnings(\)
public void actionPerformed(ActionEvent e) {
open.showOpenDialog(null);
strFilePath = open.getSelectedFile().getPath();///源文件路径 ((JButton)e.getSource()).setLabel(\已选\); txtInFile.setText(strFilePath);
System.out.println(txtInFile.getText());
System.out.println(\打开文件\); } } );
JLabel lblOut = new JLabel(\复制到:\); lblOut.setBounds(30, 125, 50, 20); txtOutFile = new JTextArea();
txtOutFile.setBounds(80,60,100,20);
JScrollPane scrout = new JScrollPane(txtOutFile) ; scrout.setBounds(80,125,265,40);
JButton btnSelectCopyTo = new JButton(\选择目标路径\); btnSelectCopyTo.setBounds(350, 125, 120, 20);
btnSelectCopyTo.addActionListener(new ActionListener() {
@SuppressWarnings(\)
public void actionPerformed(ActionEvent e) {
if(F_list.isSelectionEmpty())
open.setSelectedFile(new File(zhantie())); else
open.setSelectedFile(new
File(zhantie()+F_list.getSelectedValue())); open.showSaveDialog(null);
strFilePathCopyTo = open.getSelectedFile().getPath(); ((JButton)e.getSource()).setLabel(\已选\); txtOutFile.setText(strFilePathCopyTo);
System.out.println(txtOutFile.getText());
System.out.println(\打开文件\); } } );
JButton btnCopy = new JButton(\开始复制\); btnCopy.setBounds(130, 180, 90, 20);
btnCopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库功能较完善的文件管理器java课程设计报告毕业设计(论文)(2)在线全文阅读。
相关推荐: