Does anybody know how can I watch my applet?
I've tried to see how my applet's looking and I can't. I made three tries:
1. I tried to open the Appletviewer, but it doesn't (the console closes inmediately so I don't get a chance to write any instructions).
2. I also created a web page in dreamweaver, but it gives me an error when trying to load the applet
3. I did create a main inside the applet so I could run satanding alone, but I think this is giving me problems with the paint methods..
Any ideas? thanks
[503 byte] By [
kandua] at [2007-11-27 8:12:57]

# 3
Here's my code. It has a main because it's the only way I found to kind of watch it, but I would prefer to watch in somewhere else, to see it actually the changes are taking effect, and also to manage the paint and repaint methods.
// Copyright (c) 2000
package package14;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import oracle.jdeveloper.layout.*;
/**
* Applet
* <P>
* @author Ana M Yanes Benatuil
*/
public class Appletboxes extends JApplet {
boolean isStandalone = false;
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
/**
* Constructs a new instance.
*/
/**
* getParameter
* @param key
* @param def
* @return java.lang.String
*/
public String getParameter(String key, String def) {
if (isStandalone) {
return System.getProperty(key, def);
}
if (getParameter(key) != null) {
return getParameter(key);
}
return def;
}
public Appletboxes() {
}
/**
* Initializes the state of this instance.
*/
/**
* init
*/
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(836, 545));
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(133, 113, 96, 45));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("jButton2");
jButton2.setBounds(new Rectangle(452, 118, 96, 49));
jButton2.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
jButton2_mouseDragged(e);
}
});
jButton1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
jButton1_mouseDragged(e);
}
});
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
}
/**
* start
*/
public void start() {
}
/**
* stop
*/
public void stop() {
}
/**
* destroy
*/
public void destroy() {
}
/**
* getAppletInfo
* @return java.lang.String
*/
public String getAppletInfo() {
return "Applet Information";
}
/**
* getParameterInfo
* @return java.lang.String[][]
*/
public String[][] getParameterInfo() {
return null;
}
/**
* main
* @param args
*/
public static void main(String[] args) {
Appletboxes applet = new Appletboxes();
applet.isStandalone = true;
JFrame frame = new JFrame();
frame.setTitle("Applet Frame");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400, 420);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
}
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
}
void jButton1_mouseDragged(MouseEvent e) {
jButton1.setLocation(e.getX() + jButton1.getX() , e.getY() + jButton1.getY());
}
void jButton2_mouseDragged(MouseEvent e) {
jButton2.setLocation(e.getX() + jButton2.getX() , e.getY() + jButton2.getY());
}
void jButton1_actionPerformed(ActionEvent e) {
//public void actionPerformed(ActionEvent e) {
//JFrame f = new JFrame("other frame");
//f.getContentPane().add(yourApplet);
//f.pack();
//f.setVisible(true);
//}
}
}
kandua at 2007-7-12 19:57:24 >
