package net.rstown;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Scanner;
import javax.swing.JFrame;
public class RS2Loader extends JFrame implements AppletStub {
public static final String PAGE_ADDRESS = "http://oldschool1.runescape.com/";
private static final long serialVersionUID = -3450697819043722786L;
private static final HashMap<String, String> parameters = new HashMap<String, String>();
private static URL pageAddressUrl;
public static void main(String[] args) throws Exception {
pageAddressUrl = new URL(PAGE_ADDRESS);
String pageSource = readPageSource(PAGE_ADDRESS);
parseParameters(pageSource);
String gamepackFileName = findGamepackFileName(pageSource);
URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(
PAGE_ADDRESS + gamepackFileName) });
Applet game = (Applet) classLoader.loadClass("client").newInstance();
RS2Loader rs2Loader = new RS2Loader();
game.setStub(rs2Loader);
game.init();
game.start();
rs2Loader.add(game);
rs2Loader.setDefaultCloseOperation(EXIT_ON_CLOSE);
rs2Loader.setSize(773, 530);
rs2Loader.setTitle("Old School RuneScape Client Loader");
rs2Loader.setResizable(false);
rs2Loader.setVisible(true);
}
private static String readPageSource(String pageAddress) throws IOException {
String source = "";
Scanner scanner = new Scanner(new URL(pageAddress).openStream());
while (scanner.hasNextLine()) {
source += scanner.nextLine() + "\n";
}
scanner.close();
return source;
}
private static void parseParameters(String pageSource) {
String[] lines = pageSource.split("\n");
String paramNameBeginning = "param name=";
String valueBeginning = "value=";
for (String line : lines) {
if (!line.contains(paramNameBeginning)) {
continue;
}
int start = line.indexOf(paramNameBeginning)
+ paramNameBeginning.length() + 1;
int end = line.indexOf('"', start);
String name = line.substring(start, end);
start = line.indexOf(valueBeginning) + valueBeginning.length() + 1;
end = line.indexOf('"', start);
String value = line.substring(start, end);
parameters.put(name, value);
}
}
private static String findGamepackFileName(String pageSource) {
String gamepackFileNameStart = "archive=";
int gamepackFileNameStartIndex = pageSource
.indexOf(gamepackFileNameStart);
return pageSource.substring(gamepackFileNameStartIndex
+ gamepackFileNameStart.length(),
pageSource.indexOf('\'', gamepackFileNameStartIndex));
}
public URL getDocumentBase() {
return pageAddressUrl;
}
public URL getCodeBase() {
return pageAddressUrl;
}
public String getParameter(String name) {
return parameters.get(name);
}
public AppletContext getAppletContext() {
return null;
}
public void appletResize(int width, int height) {
}
}`
那是加载器类,它的图片在这里http://prntscr.com/yin89 Botwindow 这是 Jpanel 是我希望加载器在我打开它时显示 botwindow 的图片在这里http://prntscr .com/yin29 .
package net.rstown.gui;
import net.rstown.RS2Loader;
import net.rstown.log.Loggable;
import net.rstown.log.TextAreaLogHandler;
import net.rstown.menu.Menu;
import net.rstown.util.Configuration;
import net.rstown.util.Resources;
import javax.swing.*;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Scanner;
import java.util.logging.Logger;
public final class BotWindow extends JFrame {
private static final long serialVersionUID = 1L;
private final static Logger log = Logger.getLogger("BotWindow");
private static boolean slowGraphics;
public static boolean useSlowGraphics() {
return slowGraphics;
}
private static final BotWindow instance = new BotWindow().initialize();
@Override
public void setVisible(boolean visible) {
super.setCursor(Cursor.getDefaultCursor());
super.setVisible(visible);
}
public static final BotWindow get() {
return instance;
}
private final JScrollPane TEXT_SCROLL = new JScrollPane(22, 31);
public JScrollPane getLogScrollPane() {
return TEXT_SCROLL;
}
// private LoadingScreen screen = new LoadingScreen();
private RS2Loader loader = new RS2Loader();
private BotWindow initialize() {
setSize(768, 530);
setIconImage(Resources.Images.ICON);
setTitle(Configuration.NAME + (Configuration.OUTDATED ? " (outdated)" : "") + (Configuration.DEVMODE ? " (developer mode)" : ""));
Logger.getLogger("").addHandler(new TextAreaLogHandler());
log.info("Welcome to RsTown!");
Loggable.devlog("RsTown", "You are in developer mode!");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
TEXT_SCROLL.setViewportView(TextAreaLogHandler.TEXT_AREA);
TEXT_SCROLL.setPreferredSize(new Dimension(765, Configuration.DEVMODE ? 120 : 19));
setJMenuBar(BotMenu.get());
setLayout(new BorderLayout());
add(TEXT_SCROLL, BorderLayout.SOUTH);
//setSize(775, Configuration.DEVMODE ? 672 : 573);
setMinimumSize(new Dimension(775, Configuration.DEVMODE ? 672 : 573));
add(loader, BorderLayout.CENTER);
//add(screen, BorderLayout.CENTER);
// add(BotToolBar.get(), BorderLayout.NORTH);
SwingUtilities.updateComponentTreeUI(getContentPane());
setLocationCentered();
setVisible(true);
setResizable(false);
return this;
}
/*public void removeLoadingScreen() {
if (screen == null) return;
remove(screen);
screen = null;
setResizable(true);
}*/
private void setLocationCentered() {
final int x = Toolkit.getDefaultToolkit().getScreenSize().width / 2 - this.getWidth() / 2;
final int y = Toolkit.getDefaultToolkit().getScreenSize().height / 2 - this.getHeight() / 2;
setLocation(x, y);
}
public void toggleLog() {
final boolean small = TEXT_SCROLL.getHeight() == 19;
Menu.LOG_PLANE_TOGGLE.setIcon(new ImageIcon(small ? Resources.Images.HIDE_LOG : Resources.Images.SHOW_LOG));
TEXT_SCROLL.setPreferredSize(new Dimension(TEXT_SCROLL.getWidth(), small ? 120 : 19));
setMinimumSize(new Dimension(775, small ? 672 : 573));
if (!small) {
setSize(new Dimension(getWidth(), getHeight() - 99));
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
int lastIndex = TextAreaLogHandler.TEXT_AREA.getModel().getSize() - 1;
if (lastIndex >= 0) {
TextAreaLogHandler.TEXT_AREA.ensureIndexIsVisible(lastIndex);
}
}
});
}
private static final class LoadingScreen extends JComponent {
private static final long serialVersionUID = 1L;
public LoadingScreen() {
setPreferredSize(new Dimension(707, 500));
}
@Override
public void paint(Graphics g) {
g.drawImage(Resources.Images.LOADING_IMAGE, 0, 0, null);
}
}
}