jpcapplication.java

来自「JPC: x86 PC Hardware Emulator. 牛津大学开发的一个」· Java 代码 · 共 467 行 · 第 1/2 页

JAVA
467
字号
                            BlockDevice hda = new TreeBlockDevice(file, true);                            DriveSet drives = pc.getDrives();                            drives.setHardDrive(0, hda);                            setTitle("JPC - " + file);                        }                        else if (fileChooser == diskImageChooser)                        {                            System.out.println("loading image");                            BlockDevice device = null;                            Class blockClass = Class.forName("org.jpc.support.FileBackedSeekableIODevice");                            SeekableIODevice ioDevice = (SeekableIODevice)(blockClass.newInstance());                            ioDevice.configure(file.getPath());                            device = new RawBlockDevice(ioDevice);                            DriveSet drives = pc.getDrives();                            drives.setHardDrive(0, device);                                                    setTitle("JPC - " + file);                        }                        else if (fileChooser == snapshotChooser)                        {                            /*DataInputStream in = new DataInputStream(zip.getInputStream(entry));                              int len = in.readInt();                              String[] args = new String[len];                              for (int i=0; i<len; i++)                              args[i] = in.readUTF();                              zip.close();*/                            //pc = PC.createPC(args, new VirtualClock());                             //monitor = new PCMonitor(pc);                            System.out.println("Loading a snapshot of JPC");                            pc.loadState(file);                            System.out.println("Loading data");                            pc.getGraphicsCard().resizeDisplay(monitor);                            monitor.loadState(file);                            System.out.println("done");                        }                    }                }                catch (IndexOutOfBoundsException e)                {                    //there were too many files in the directory tree selected                    System.out.println("too many files");                    JOptionPane.showMessageDialog(this, "The directory you selected contains too many files. Try selecting a directory with fewer contents.", "Error loading directory", JOptionPane.ERROR_MESSAGE, null);                    return;                }                catch (Exception e)                {                    System.err.println(e);                }            }                        monitor.stopUpdateThread();            if (reboot)                pc.reset();            monitor.revalidate();            monitor.requestFocus();                        if (reboot)                reset();        }    }    private void saveSnapShot()    {        if (running)            stop();        int returnVal = snapshotChooser.showDialog(this, "Save JPC Snapshot");        File file = snapshotChooser.getSelectedFile();                if (returnVal == 0)            try            {                DataOutputStream out = new DataOutputStream(new FileOutputStream(file));                ZipOutputStream zip = new ZipOutputStream(out);                                pc.saveState(zip);                monitor.saveState(zip);                zip.close();            }            catch (Exception e)            {                System.err.println(e);            }                start();    }    private void showAboutUs()    {        Object[] buttons = {"Visit our Website", "Ok"};        int i =JOptionPane.showOptionDialog(this, aboutUsText, "JPC info", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, buttons, buttons[1]);        if (i == 0)        {            Desktop desktop = null;            if (Desktop.isDesktopSupported())             {                desktop = Desktop.getDesktop();                try                {                    desktop.browse(new URI("http://www-jpc.physics.ox.ac.uk"));                }                catch (Exception e)                {                    System.err.println(e);                }            }        }    }    private void changeFloppy(int i)    {        int returnVal = floppyImageChooser.showDialog(this, "Load Floppy Drive Image");        File file = floppyImageChooser.getSelectedFile();                if (returnVal == 0)            try            {                BlockDevice device = null;                Class blockClass = Class.forName("org.jpc.support.FileBackedSeekableIODevice");                SeekableIODevice ioDevice = (SeekableIODevice)(blockClass.newInstance());                ioDevice.configure(file.getPath());                device = new RawBlockDevice(ioDevice);                pc.setFloppy(device, i);            }            catch (Exception e)            {                System.err.println(e);            }    }    public void actionPerformed(ActionEvent evt)    {        super.actionPerformed(evt);        if (evt.getSource() == doubleSize)        {            if (doubleSize.isSelected())                setBounds(100, 100, (WIDTH*2)+20, (HEIGHT*2)+70);            else                setBounds(100, 100, WIDTH+20, HEIGHT+70);        }        else if (evt.getSource() == load)            load("a directory", diskDirChooser, true);        else if (evt.getSource() == image)        {            System.out.println("received image event");            load("a disk image", diskImageChooser, true);        }        else if ((evt.getSource() == dosgamesImage) || (evt.getSource() == moregamesImage) || (evt.getSource() == mousegamesImage))        {            String fileName = "dosgames.img";            if (evt.getSource() == moregamesImage)                fileName = "moregames.img";            else if (evt.getSource() == mousegamesImage)                fileName = "mousegames.img";            load(fileName, null, true);        }        else if (evt.getSource() == loadSnapshot)            load("a snapshot", snapshotChooser, false);        else if (evt.getSource() == saveSnapshot)            saveSnapShot();        else if (evt.getSource() == changeFloppyA)            changeFloppy(0);        else if (evt.getSource() == changeFloppyB)            changeFloppy(1);        else if (evt.getSource() == gettingStarted)        {            stop();            getMonitorPane().setViewportView(licence);        }        else if (evt.getSource() == aboutUs)            showAboutUs();    }        private static class ImageFileFilter extends javax.swing.filechooser.FileFilter    {        public boolean accept(File f)         {            if (f.isDirectory())                 return true;                            String extension = getExtension(f);            if ((extension != null) && (extension.equals("img")))                return true;            return false;        }                    private String getExtension(File f)         {            String ext = null;            String s = f.getName();            int i = s.lastIndexOf('.');                            if (i > 0 &&  i < s.length() - 1)             {                ext = s.substring(i+1).toLowerCase();            }            return ext;        }        public String getDescription()        {            return "Shows disk image files and directories";        }    }    public static void main(String[] args) throws Exception    {         try        {            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());        }        catch (Exception e) {}        if (args.length == 0)            args = defaultArgs;                PC pc = PC.createPC(args, new VirtualClock());         JPCApplication app = new JPCApplication(args, pc);                app.setBounds(100, 100, WIDTH+20, HEIGHT+70);        try        {            app.setIconImage(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("resource/jpcicon.png")));        }        catch (Exception e) {}                app.validate();        app.setVisible(true);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?