📄 harddiskmanagershow.java
字号:
package desktop;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.UIManager;
import java.lang.*;
import java.io.*;
import Global.*;
import myException.*;
//import OS.*;
import Manager.*;
import javax.swing.tree.*;
public class HardDiskManagerShow extends JFrame implements ActionListener
{
private JButton add;
private JButton sub;
private JButton show;
private JTree tree;
private DefaultMutableTreeNode root;
private DefaultTreeModel treeModel;
private Manager.HardDiskManager HDM;
private Manager.MemoryManager MM;
private JPanel JP_contentPane;
private DetailTables table;
private JScrollPane JS_table;
private JScrollPane JS_tree;
private static int lastIndex;
public HardDiskManagerShow()
{
Global.init(1000,10,3,10);
this.jbInit();
}
public static void main(String args[])
{
try {
LookAndFeel alloy = new com.incors.plaf.alloy.AlloyLookAndFeel();
UIManager.setLookAndFeel(alloy);
Font font =new Font("宋体",Font.PLAIN,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<names.length;i++)UIManager.put(names[i]+".font",font);
UIManager.put("Label.foreground",Color.black);
UIManager.put("Border.foreground",Color.black);
UIManager.put("TitledBorder.titleColor",Color.black);
new HardDiskManagerShow();
}catch(Exception e){
e.printStackTrace();
}
}
private void jbInit()
{
add = new JButton("add");
sub = new JButton("sub");
show = new JButton("show");
JP_contentPane = new JPanel(null);
String Columns[] = new String[4];
Columns[0] = "ID";
Columns[1] = "名称";
Columns[2] = "链表序号";
Columns[3] = "文件大小";
table = new DetailTables(Columns);
JS_table = new JScrollPane(table);
HDM = new Manager.HardDiskManager();
MM = new MemoryManager();
tree = null;
treeModel = null;
root=new DefaultMutableTreeNode("虚拟硬盘");
tree=new JTree(root);
treeModel=(DefaultTreeModel)tree.getModel();
JS_tree = new JScrollPane(tree);
//添加事件
add.addActionListener(this);
sub.addActionListener(this);
show.addActionListener(this);
//添加组件
JP_contentPane.add(add);
JP_contentPane.add(sub);
JP_contentPane.add(show);
//JS_tree.add(tree);
JP_contentPane.add(JS_tree);
JP_contentPane.add(JS_table);
//组件定位
add.setBounds(310,100,100,30);
sub.setBounds(310,150,100,30);
show.setBounds(310,190,100,30);
JS_table.setBounds(0,0,300,400);
JS_tree.setBounds(420,0,300,400);
Container Desktop_frame=getContentPane();
Desktop_frame.add(JP_contentPane);
this.setSize(800,450);
this.setVisible(true);
//关闭按钮
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == add)
{
this.addFile("root\\job.txt");
}//end if
else if (e.getSource() == sub)
{
//HardDiskManager HDM=new HardDiskManager();
TreePath treepath=tree.getSelectionPath();
if (treepath!=null)
{
//下面两行取得选取节点的父节点.
DefaultMutableTreeNode selectionNode=(DefaultMutableTreeNode)treepath.getLastPathComponent();
TreeNode parent=(TreeNode)selectionNode.getParent();
//TreeNode children=(TreeNode)selectionNode.getFirstChild();
if (parent!=null&&(!selectionNode.isLeaf()))
{
//由DefaultTreeModel的removeNodeFromParent()方法删除节点,包含它的子节点。
treeModel.removeNodeFromParent(selectionNode);
int id = Integer.parseInt(selectionNode.toString());
try
{
HDM.RemoveFile(id);
}
catch(myException e1){System.out.println(e1);}
System.out.println(selectionNode.toString());
table.RemoveAll();
String ss[] = new String[4];
for(int i=0;i<Global.HDTABLE.last();i++)
{
ss[0] = ""+HDM.getID(i);
ss[1] = HDM.getFileName(i);
ss[2] = ""+HDM.getIndex(i);
ss[3] = ""+HDM.Size(i);
table.addRow(ss);
}//end for
}//end if
}//end if
}//end else if
else if(e.getSource() == show)
{
MemoryShow memoryshow = new MemoryShow();
memoryshow.setSize(500,450);
memoryshow.setVisible(true);
}
}//end actionPerformed
public void addFile(String path)
{
try
{
String ss[] = new String[4];
HDM.GetFile(path);
int index = HDM.getIndex();
int id = HDM.getID(index);
//String name = HDM.getFileName(index);
DefaultMutableTreeNode pnode = new DefaultMutableTreeNode(""+id);
treeModel.insertNodeInto(pnode, root, root.getChildCount());
for(int i=0;i<HDM.Size(0);i++)
{
DefaultMutableTreeNode leafnode = new DefaultMutableTreeNode(HDM.Get(0,i));
treeModel.insertNodeInto(leafnode, pnode, pnode.getChildCount());
}
table.RemoveAll();
for(int i=0;i<Global.HDTABLE.last();i++)
{
ss[0] = ""+HDM.getID(i);
ss[1] = HDM.getFileName(i);
ss[2] = ""+HDM.getIndex(i);
ss[3] = ""+HDM.Size(i);
table.addRow(ss);
}
try
{
MM.newTable(id);
int pcb[] = new int[9];
pcb[0] = id;
pcb[1] = 0;
pcb[2] = 0;
pcb[3] = 0;
pcb[4] = 0;
pcb[5] = 0;
pcb[6] = 0;
pcb[7] = 0;
pcb[8] = 0;
Global.PCBLIST.addFirst(pcb);
}
catch(myException e1){System.out.println(e1);}
}
catch(IOException e1){System.out.println(e1);}
catch(myException e1){System.out.println(e1);}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -