mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 08:39:09 +00:00
Painting on any applet
This commit is contained in:
@@ -165,7 +165,6 @@ public class Context {
|
||||
serverProvider.injectHooks();
|
||||
Core.verbose("Done.");
|
||||
Core.verbose("Fetching game applet...");
|
||||
;
|
||||
gameApplet = serverProvider.fetchApplet();
|
||||
if (getClient() == null) {
|
||||
setClientInstance(gameApplet);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import org.parabot.core.ui.components.PaintComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class BotDialog extends JDialog {
|
||||
private static final long serialVersionUID = 521800552287194673L;
|
||||
|
||||
public BotDialog(BotUI botUI) {
|
||||
super(botUI);
|
||||
botUI.setDialog(this);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
setUndecorated(true);
|
||||
setBackground(new Color(0, 0, 0, 0));
|
||||
setContentPane(new PaintComponent(botUI.getSize()));
|
||||
setPreferredSize(botUI.getSize());
|
||||
setSize(botUI.getSize());
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ import org.parabot.core.ui.components.GamePanel;
|
||||
import org.parabot.core.ui.components.LogArea;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -20,10 +22,11 @@ import java.awt.event.ActionListener;
|
||||
* @author Dane, Everel
|
||||
*
|
||||
*/
|
||||
public class BotUI extends JFrame implements ActionListener {
|
||||
public class BotUI extends JFrame implements ActionListener, ComponentListener {
|
||||
|
||||
private static final long serialVersionUID = -2126184292879805519L;
|
||||
private static BotUI instance;
|
||||
private static JDialog dialog;
|
||||
|
||||
public static BotUI getInstance() {
|
||||
return instance == null ? instance = new BotUI() : instance;
|
||||
@@ -37,6 +40,7 @@ public class BotUI extends JFrame implements ActionListener {
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||
this.setLayout(new BorderLayout());
|
||||
this.addComponentListener(this);
|
||||
|
||||
int iToolbarHeight = 24;
|
||||
int iGameHeight = 503;
|
||||
@@ -85,8 +89,10 @@ public class BotUI extends JFrame implements ActionListener {
|
||||
panel.add(scrlConsole);
|
||||
|
||||
this.add(panel, BorderLayout.CENTER);
|
||||
|
||||
SwingUtil.finalize(this);
|
||||
|
||||
pack();
|
||||
setVisible(true);
|
||||
new BotDialog(this);
|
||||
|
||||
LogArea.log("parabot " + Configuration.BOT_VERSION +" started");
|
||||
}
|
||||
@@ -107,4 +113,32 @@ public class BotUI extends JFrame implements ActionListener {
|
||||
System.out.println("Invalid command: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setDialog(JDialog dialog) {
|
||||
BotUI.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
if(dialog == null) {
|
||||
return;
|
||||
}
|
||||
Point gameLocation = GamePanel.getInstance().getLocationOnScreen();
|
||||
dialog.setLocation(gameLocation.x, gameLocation.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
* The panel that is painted on
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class PaintComponent extends JPanel {
|
||||
private static final long serialVersionUID = 4653612412080038193L;
|
||||
|
||||
public PaintComponent(Dimension size) {
|
||||
setPreferredSize(size);
|
||||
setSize(size);
|
||||
setOpaque(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
System.out.println("paint");
|
||||
g.setColor(Color.red);
|
||||
g.drawString("hi", 10, 10);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user