⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eclipseswt.java

📁 手机模拟器源代码,可以在网页上调用applet应用来摸拟手机,在线体验手机游戏和运用.可以在网页上自定义手机外观.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  MicroEmulator *  Copyright (C) 2001-2003 Bartek Teodorczyk <barteo@it.pl> * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package com.barteo.emulator.app;			  import java.io.ByteArrayOutputStream;import java.io.File;import java.io.PrintStream;import java.net.MalformedURLException;import java.net.URL;import java.util.Enumeration;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;import org.eclipse.swt.SWT;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.events.ShellEvent;import org.eclipse.swt.events.ShellListener;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.Cursor;import org.eclipse.swt.graphics.DeviceData;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.FontData;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.graphics.Region;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.List;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;import com.barteo.emulator.DisplayComponent;import com.barteo.emulator.EmulatorContext;import com.barteo.emulator.MIDletBridge;import com.barteo.emulator.app.launcher.Launcher;import com.barteo.emulator.app.ui.swt.SwtDeviceComponent;import com.barteo.emulator.app.ui.swt.SwtSelectDeviceDialog;import com.barteo.emulator.app.util.DeviceEntry;import com.barteo.emulator.app.util.ProgressJarClassLoader;import com.barteo.emulator.device.Device;import com.barteo.emulator.device.DeviceDisplay;import com.barteo.emulator.device.DeviceFactory;import com.barteo.emulator.device.FontManager;import com.barteo.emulator.device.InputMethod;import com.barteo.emulator.device.swt.SwtDevice;import com.barteo.emulator.device.swt.SwtDeviceDisplay;import com.barteo.emulator.device.swt.SwtFontManager;import com.barteo.emulator.device.swt.SwtInputMethod;import com.barteo.emulator.util.JadMidletEntry;public class EclipseSwt extends Common{	public static Shell shell;	private static SwtDeviceComponent devicePanel;	private boolean initialized = false;  	private SwtSelectDeviceDialog selectDeviceDialog;	private DeviceEntry deviceEntry;  	private KeyListener keyListener = new KeyListener()	{    		public void keyTyped(KeyEvent e)		{		}    		public void keyPressed(KeyEvent e)		{//			devicePanel.keyPressed(e);		}    		public void keyReleased(KeyEvent e)		{//			devicePanel.keyReleased(e);		}    	};       	private ShellListener shellListener = new ShellListener()	{		public void shellActivated(ShellEvent e) 		{		}		public void shellClosed(ShellEvent e) 		{			close();		}		public void shellDeactivated(ShellEvent e) 		{		}		public void shellDeiconified(ShellEvent e) 		{			try {				MIDletBridge.getMIDletAccess(getLauncher().getCurrentMIDlet()).startApp();			} catch (MIDletStateChangeException ex) {				System.err.println(ex);			}		}		public void shellIconified(ShellEvent e) 		{			MIDletBridge.getMIDletAccess(getLauncher().getCurrentMIDlet()).pauseApp();		}	};   	EclipseSwt(Shell shell, Device device, String captureFile)	{		super(new EmulatorContext()		{			private ProgressJarClassLoader loader = new ProgressJarClassLoader();						private InputMethod inputMethod = new SwtInputMethod();						private DeviceDisplay deviceDisplay = new SwtDeviceDisplay(this);    			private FontManager fontManager = new SwtFontManager();						public ClassLoader getClassLoader()			{				return loader;			}    			public DisplayComponent getDisplayComponent()			{				return devicePanel.getDisplayComponent();			}			public Launcher getLauncher() 			{				return getLauncher();			}            public InputMethod getDeviceInputMethod()            {                return inputMethod;            }            public DeviceDisplay getDeviceDisplay()            {                return deviceDisplay;            }			public FontManager getDeviceFontManager() 			{				return fontManager;			}    		});		GridLayout layout = new GridLayout(1, false);		shell.setLayout(layout);		shell.setLayoutData(new GridData(GridData.FILL_BOTH));		shell.setText("Microemu");//		addWindowListener(windowListener);		    		Config.loadConfig("config.xml");		shell.addKeyListener(keyListener);		devicePanel = new SwtDeviceComponent(shell);		devicePanel.setLayoutData(new GridData(GridData.FILL_BOTH));				this.captureFile = captureFile;		if (device == null) {			selectDeviceDialog = new SwtSelectDeviceDialog(shell);			setDevice(selectDeviceDialog.getSelectedDeviceEntry());		} else {			setDevice(device);		}    		initialized = true;	}        	public DeviceEntry getDevice()	{		return deviceEntry;	}    	public void setDevice(DeviceEntry entry)	{		if (DeviceFactory.getDevice() != null) {//			((SwtDevice) DeviceFactory.getDevice()).dispose();		}				ProgressJarClassLoader loader = (ProgressJarClassLoader) emulatorContext.getClassLoader();		try {			Class deviceClass = null;			if (entry.getFileName() != null) {				loader.addRepository(						new File(Config.getConfigPath(), entry.getFileName()).toURL());				deviceClass = loader.findClass(entry.getClassName());			} else {				deviceClass = Class.forName(entry.getClassName());			}			SwtDevice device = (SwtDevice) deviceClass.newInstance();			this.deviceEntry = entry;			setDevice(device);		} catch (MalformedURLException ex) {			System.err.println(ex);          		} catch (ClassNotFoundException ex) {			System.err.println(ex);          		} catch (InstantiationException ex) {			System.err.println(ex);          		} catch (IllegalAccessException ex) {			System.err.println(ex);          		}	}	protected void setDevice(SwtDevice device)	{		super.setDevice(device);		device.init(emulatorContext);		shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));	}    	protected void loadFromJad(URL jadUrl)	{				try {			for (Enumeration e = jad.getMidletEntries().elements(); e.hasMoreElements(); ) {				JadMidletEntry jadEntry = (JadMidletEntry) e.nextElement();				Class midletClass = emulatorContext.getClassLoader().loadClass(jadEntry.getClassName());				loadMidlet(jadEntry.getName(), midletClass);			}			notifyDestroyed();		} catch (ClassNotFoundException ex) {			System.err.println(ex);		}        	}	public static void main(String args[])	{		DeviceData data = new DeviceData();		data.tracking = true;				Display display = new Display(data);		shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.ON_TOP);		    		MIDlet m = null;//		Sleak sleak = app.new Sleak (display);//		sleak.open ();		Device device = null;		String captureFile = null;		URL jadUrl = null;		Class midletClass = null;		if (args.length > 0) {			for (int i = 0; i < args.length; i++) {				if (args[i].equals("--deviceClass")) {					i++;					try {						Class deviceClass = Class.forName(args[i]);						device = (Device) deviceClass.newInstance();					} catch (ClassNotFoundException ex) {						System.err.println(ex);          					} catch (InstantiationException ex) {						System.err.println(ex);          					} catch (IllegalAccessException ex) {						System.err.println(ex);          					}									} else if (args[i].equals("--captureFile")) {					i++;

⌨️ 快捷键说明

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