import javaawt;
import javaawtevent;
import javaxswing;
import javatextDateFormat;
import javaxswingevent;
import javaxswingtable;
import javaxswingtree;
import javaxswingfilechooser;
import javaio;
import javautil;
public class WinExplorer extends JFrame implements TreeSelectionListener{
JPanel contentPane=(JPanel)getContentPane();;
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("文件");
JMenuItem menuItemExit = new JMenuItem("退出");
JToolBar toolBar = new JToolBar();
JButton bttUp = new JButton();
Icon iconUp=UIManagergetIcon("FileChooserupFolderIcon");
JLabel statusBar = new JLabel();
DetailTable detailTable = new DetailTable();
JScrollPane sp = new JScrollPane(detailTable);
JSplitPane split = new JSplitPane();
FileSystemView fileSystemView=FileSystemViewgetFileSystemView();
FileNode root=new FileNode(fileSystemViewgetRoots()[0]);
DefaultTreeModel treeModel=new DefaultTreeModel(root);
JTree tree = new JTree(treeModel);
public static void main(String argv[]){
try {
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName());
Font font=new Font("宋体",FontPLAIN,12);
String names[]={"Label","CheckBox","PopupMenu","TextPane",
"MenuItem","CheckBoxMenuItem","JRadioButtonMenuItem",
"ComboBox","Button","Tree","ScrollPane","TabbedPane",
"EditorPane","TitledBorder","Menu","TextArea","OptionPane",
"MenuBar","ToolBar","ToggleButton","ToolTip","ProgressBar",
"TableHeader","Panel","List","ColorChooser","PasswordField",
"TextField","Table","Label","Viewport","RadioButtonMenuItem",
"RadioButton"};
for(int i=0;i<nameslength;i++)UIManagerput(names[i]+"font",font);
UIManagerput("Labelforeground",Colorblack);
UIManagerput("Borderforeground",Colorblack);
UIManagerput("TitledBordertitleColor",Colorblack);
new WinExplorer()show();
}catch(Exception e){
eprintStackTrace();
}
}
public WinExplorer() {
contentPanesetLayout(new BorderLayout());
Dimension dimension = getToolkit()getScreenSize();
int i = (dimensionwidth - 640) / 2;
int j = (dimensionheight - 480) / 2;
setBounds(i,j,640,480);
setTitle("资源管理器");
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
setJMenuBar(menuBar);
statusBarsetText(" ");
menuItemExitaddActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {Systemexit(0);}
});
bttUpsetIcon(iconUp);
bttUpaddActionListener(new javaawteventActionListener() {
public void actionPerformed(ActionEvent e) {
try{
TreePath upPath=treegetSelectionPath()getParentPath();
if(upPath!=null){
treesetSelectionPath(upPath);
treescrollPathToVisible(upPath);
}
}catch(Exception ex){}
}
});
splitsetDividerSize(6);
splitsetLeftComponent(new JScrollPane(tree));
splitsetRightComponent(sp);
splitsetDividerLocation(180);
spgetViewport()setBackground(Colorwhite);
menuFileadd(menuItemExit);
menuBaradd(menuFile);
contentPaneadd(toolBar, BorderLayoutNORTH);
toolBaradd(bttUp, null);
contentPaneadd(statusBar, BorderLayoutSOUTH);
contentPaneadd(split, BorderLayoutCENTER);
treeaddTreeExpansionListener(new MyExpandsionListener());
treesetCellRenderer(new MyTreeCellRenderer());
treeaddTreeSelectionListener(this);
treesetSelectionRow(0);
treesetComponentOrientation(ComponentOrientationUNKNOWN);
}
public void valueChanged(TreeSelectionEvent e){
Object obj=treegetLastSelectedPathComponent();
if(obj==null)return;
else detailTablesetParent(((FileNode)obj)getFile());
}
class MyTreeCellRenderer extends DefaultTreeCellRenderer {
public MyTreeCellRenderer() {}
public Component getTreeCellRendererComponent(JTree tree,Object value,
boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus) {
supergetTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
setIcon(fileSystemViewgetSystemIcon(((FileNode)value)getFile()));
return this;
}
}
class MyExpandsionListener implements TreeExpansionListener {
public MyExpandsionListener() {}
public void treeExpanded(TreeExpansionEvent event) {
if(eventgetPath() == null){
return;
}
treesetCursor(new Cursor(CursorWAIT_CURSOR));
TreePath path = eventgetPath();
FileNode node = (FileNode)pathgetLastPathComponent();
nodeexplore();
treeModelnodeStructureChanged(node);
treesetCursor(new Cursor(CursorDEFAULT_CURSOR));
}
public void treeCollapsed(TreeExpansionEvent event) {}
}
class FileNode extends DefaultMutableTreeNode {
private boolean explored = false;
public FileNode(File file) { setUserObject(file); }
public boolean getAllowsChildren() { return isDirectory(); }
public boolean isLeaf() { return !isDirectory();}
public File getFile() { return (File)getUserObject(); }
public boolean isExplored() { return explored; }
public void setExplored(boolean b){ explored=b;}
public boolean isDirectory() { return getFile()isDirectory();}
public String toString() {
File file = (File)getUserObject();
String filename = filetoString();
int index = filenamelastIndexOf(Fileseparator);
return (index != -1 && index != filenamelength()-1)
filenamesubstring(index+1) : filename;
}
public void explore() {
if(!isExplored()) {
File file = getFile();
File[] children = filelistFiles();
if(children==null||childrenlength==0)return;
for(int i=0; i < childrenlength; ++i)
{
File f=children[i];
if(fisDirectory())add(new FileNode(children[i]));
}
explored = true;
}
}
}
class DetailTable extends JTable{
DetailTableModel model=new DetailTableModel();
public DetailTable(){
setModel(model);
setShowGrid(false);
TableColumnModel colModel = getColumnModel();
for (int i=0;i<3;i++)
colModelgetColumn(i)setCellRenderer(new DetailsTableCellRenderer());
setRowHeight(18);
thisaddMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
if(egetClickCount()==2){
for (int i = 0; i <getRowCount(); i++) {
if(getCellRect(i,0,true)contains(egetPoint())){
openSelect();
break;
}
}
}
}
});
}
public void openSelect(){
Object obj=modelgetValueAt(getSelectedRow(),0);
if(obj==null)return;
File f=(File)obj;
if(fisDirectory()){
//expand tree
}else{
//open select file
}
}
public void setParent(File parent){
modelremoveAllRows();
File list[]=parentlistFiles();
if(list==null)return;
Vector vDir=new Vector(),vFile=new Vector();
for (int i = 0; i < listlength; i++) {
if(list[i]isDirectory())vDiradd(list[i]);
else vFileadd(list[i]);
}
sortElements(vFile);
sortElements(vDir);
for (int i = 0; i < vDirsize(); i++)modeladdFile((File)vDirelementAt(i));
for (int i = 0; i < vFilesize(); i++)modeladdFile((File)vFileelementAt(i));
}
public void sortElements(Vector v)
{
for(int i=0;i<vsize();i++)
{
int k=i;
for(int j=i+1;j<vsize();j++){
File fa=(File)velementAt(j);
File fb=(File)velementAt(k);
if(fileSystemViewgetSystemDisplayName(fa)toLowerCase()compareTo(
fileSystemViewgetSystemDisplayName(fb)toLowerCase())<0)k=j;
}
if(k!=i)swap(k,i,v);
}
}
private void swap(int loc1,int loc2,Vector v){
Object tmp=velementAt(loc1);
vsetElementAt(velementAt(loc2),loc1);
vsetElementAt(tmp,loc2);
}
class DetailTableModel extends DefaultTableModel {
public DetailTableModel() {
addColumn("名称");
addColumn("大小");
addColumn("修改时间");
}
public void addFile(File f){
addRow(new Object[]{f,new Double(flength()/1024),
new javasqlDate(flastModified())});
}
public void removeAllRows(){
while(getRowCount()!=0) removeRow(0);
}
public boolean isCellEditable(int row, int column) {return false;}
}
class DetailsTableCellRenderer extends DefaultTableCellRenderer {
DetailsTableCellRenderer() {}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (column == 1){
setHorizontalAlignment(SwingConstantsTRAILING);
isSelected=hasFocus=false;
}else if(column==2){
setHorizontalAlignment(SwingConstantsCENTER);
isSelected=hasFocus=false;
}else setHorizontalAlignment(SwingConstantsLEADING);
return supergetTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
}
public void setValue(Object value) {
setIcon(null);
if (value instanceof File) {
File file = (File)value;
setText(fileSystemViewgetSystemDisplayName(file));
setIcon(fileSystemViewgetSystemIcon(file));
}else{
supersetValue(value);
}
}
}
}
}
你双击左面的桌面图标就可以浏览了,别双击字。
在delphi的Additional里面有一个TrayIcon组件,可以轻松实现这个功能:新建工程,添加一个TrayIcon组件。代码:
uses shellapiprocedure TForm1FormCreate(Sender: TObject);
begin
SetWindowLong(Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//在任务栏隐藏程序
TrayIcon1Visible:=True;//在托盘显示程序图标
TrayIcon1Hint:='托盘程序';//提示信息
end;
end
以上就是关于程序最小化问题!全部的内容,包括:程序最小化问题!、c# 用代码打开外部程序托盘,并直接进入托盘状态,急急急、急需一段java小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)