*
The moose likes Applets and the fly likes snooker application conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "snooker application conversion" Watch "snooker application conversion" New topic
Author

snooker application conversion

macca palmer
Greenhorn

Joined: Sep 15, 2003
Posts: 3
Hi there. I've got a snooker application i want to convert to an applet but i'm having serious problems. I keep getting the following runtime message:
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at sun.applet.AppletSecurity.checkAccess(AppletSecurity.java:136)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:287)
at java.lang.Thread.init(Thread.java:286)
at java.lang.Thread.<init>(Thread.java:332)
at SnookerSim.start(SnookerSim.java:153)
at sun.applet.AppletPanel.run(AppletPanel.java:355)
at java.lang.Thread.run(Thread.java:536)
I've looked at all the docs about this - runtimepermissions, threads, applets - but I'm not getting anywhere. I think it must be a thread problem - thats what's causing the error at line 153 - but since i don't know why its causing the error i don't know how to fix it! The code for the applet class is below. There are also a number of other classes used - a Table class which in turn uses Pocket,Ball and Cushion classes. The applet paints the table, which in turn paints all its objects. I haven't included all these classes cos they're not the problem - or are they?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.security.AccessControlException;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class SnookerSim
extends Applet
implements Runnable, MouseListener, MouseMotionListener, KeyListener {
public Thread myThread;
int m_fps = 30;
int x, y;
static boolean m_bRepaintAll = true;
private Dimension m_dimWin = new Dimension(0, 0);
String key;
public Table m_theTable;
static Frame window;
//MouseMotionListener************************************
public void mouseDragged(MouseEvent e) {
//if(e.getButton() == MouseEvent.BUTTON1) {
x = e.getX();
y = e.getY();
m_theTable.m_cue.drag(x, y);
//mouse/cue dragged back while button pressed
//}
repaint();
}
public void mouseMoved(MouseEvent e) {
}
//MouseListener*******************************************
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
x = e.getX();
y = e.getY();
Point p = new Point();
XYVector v = new XYVector(x, y);
p = m_theTable.m_cue.getCentre();
//aim focussed over centre of white ball
if (m_theTable.m_cue.getBall().testCollision(v)) {
// test if mouse was pressed over white ball
m_theTable.m_cue.activate(p.x, p.y);
} else {
//power/aim gauge is not drawn
}
repaint();
}
}
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
x = e.getX();
y = e.getY();
m_theTable.store();
m_theTable.m_cue.release(x, y); //mouse/cue released
repaint();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
//KeyListener************************************************
public void keyTyped(KeyEvent e) {
char key_char = e.getKeyChar();
key = String.valueOf(key_char).toUpperCase();
if (key.equals("R") || key.equals("S")) { // Retake shot
m_theTable.restore();
m_bRepaintAll = true;
}
if (key.equals("N")) { // Reset Table
reset();
m_bRepaintAll = true;
}
if (key.equals("=")) { // Increase Ball size
Table.setBallRadius(Table.getBallRadius() + 1);
reset();
m_bRepaintAll = true;
}
if (key.equals("-")) { // Decrease Ball size
Table.setBallRadius(Table.getBallRadius() - 1);
reset();
m_bRepaintAll = true;
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
// SnookerSim Class Constructor
//--------------------------------------------------------------------------
public SnookerSim() {
//nothing here
}
//APPLET methods**************************************************************
public void init() {
setSize(800, 400);
reset();
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
}
public void start() {
myThread = new Thread(this);
if (myThread != null) {
myThread.start(); //run() method automatically called
}
}
public void stop() {
myThread = null;
}
//THREAD****************************************************************
// method from Thread-Runnable interface - called when thread started
public void run() {
int nSleepTime = 1000 / m_fps;
int nIterationsPerFrame = 800 / m_fps;
while (true) {
try {
for (int t = 0; t < nIterationsPerFrame; t++) {
m_theTable.Animate();
}
repaint();
Thread.sleep(nSleepTime);
} catch (InterruptedException e) {
stop();
}
}
}
//reset table to new table*************************************************
public void reset() {
m_theTable = new Table(800, 400);
}
// Graphics*****************************************************************
public void update(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Dimension dim = this.getSize();
if (dim.width > m_dimWin.width || dim.height > m_dimWin.height) {
m_bRepaintAll = true;
m_dimWin = new Dimension(dim.width, dim.height);
}
if (m_bRepaintAll) {
paint(g2);
} else {
m_theTable.paint(g2);
}
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (m_theTable != null) {
m_theTable.paintAll(g2);
}
m_bRepaintAll = false;
}
}
Now, i've seached the java.sun forums and this one also and have found one person with a simlar problem to me - unfortunately no one answered their screams for help! I'm desperate - if anyone could help me I'd be very much obliged.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi "mc"
Welcome to JavaRanch! We don't have many rules around these here parts, but we do got one: our naming policy requires that yer handle include a real-lookin' first n' last name. Please change yours ASAP.
As to your problem: it looks as though your configuration for appletviewer or the Java plugin is set up to disallow thread creation. Have you edited a ".policy" security policy file anyplace? If so, you may have created this restrictive policy yourself. Otherwise, it might have been set up by some tool or an ornery sysadmin.
See you around the Ranch!


[Jess in Action][AskingGoodQuestions]
macca palmer
Greenhorn

Joined: Sep 15, 2003
Posts: 3
Aha! thanks pardner! I was tearing my hair trying to figure out what was wrong with the code. Trouble is, I haven't altered anything to make the problem occur - well, not to my knowledge anyways. Well, I will look into this tomorrow - - its time for me to bed-down here in blighty. Thanks again.
macca palmer
Greenhorn

Joined: Sep 15, 2003
Posts: 3
Well, the problem stems from the IDE I'm using - Eclipse 2.1. It must use a modified policy file or something because the applet works fine when run outside. Does anyone know how to alter Eclipse in order to stop the previously described permissions error? I've checked the documentation but can't find anything to help. Is there an Eclipse guru out there who can solve my little problem?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: snooker application conversion
 
Similar Threads
Messagebox with Mouseevent
Drawing/moving problem: how to define destination? (code included)
Popup menu not responding with mouse event
How to reuse mouseClicked() in the same code to do diffrent tasks?
Zooming in and out - cursor not in the right place