Interest Ask.
I did not find a reliable way to affect the AppletViewer, not without using a script on Windows to run it from batch file mode, and even that did not work.
An alternative is to write test code so that the applet runs in a JFrame, which you can easily center.
Add the main method for your applet:
public class TheApplet extends JApplet { int width, height; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( Color.orange ); for ( int i = 0; i < 10; ++i ) { g.drawLine( width / 2, height / 2, i * width / 10, 0 ); } } public static void main(String args[]) { TheApplet applet = new TheApplet(); JFrame frame = new JFrame("Your Test Applet"); frame.getContentPane().add(applet); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(640,480); frame.setLocationRelativeTo(null); frame.setVisible(true); applet.init(); } }
This should work if I did not miss something - I updated its working code, which I have running on my machine.
Ewald
source share