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]
# 1
one idea to improve your chances of getting a useful answer is to, um, post your applet code here. just a thought.
petes1234a at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 2
please don't forget the code tags. if unsure about these, have a look here: http://forum.java.sun.com/help.jspa?sec=formatting
petes1234a at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 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 > top of Java-index,Desktop,Core GUI APIs...
# 4

Why is you class so complicated?

Did I not just give you a simple 5 line program to run as a simple demo applet in your last posting?

In addition to the java class file you need an HTML file to load the applet. Using the code I gave you in your last posting this html file could simply look like this:

<applet code="AppletTest.class" width="300" height="100"></applet>

Then from the command you invoke the applet by using:

appletviewer AppletTest.html

> and also to manage the paint and repaint methods.

You don't manage the paint and repaint methods, so I'm not sure what you are asking.

camickra at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 5
hi!your code is not compilable because of import oracle.jdeveloper.layout.*; so you need to make a class which can compile on its own. and this runs as applet as well fine in my machine after i remove that line from your code. which IDE you are using? regardsAniruddha
Aniruddha-Herea at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 6
Hi Camickr, your simple 5 line program is not compiling and it's not generating the .class fileWhen I open the applet viewer, which is located in C:\j2sdk1.4.2_04\bin, the window closes inmediately, and I don't have time left to write any commands on it...Any ideas? thank
kandua at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 7
Hi Aniruddha, I'm working with Jdeveloper 3.2.2 (Build 915). IDE 3.2.916I tried commenting the import oracle.jdeveloper.layout.*; but it still doesn't work...Any ideas? thank you
kandua at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...
# 8
can you write html file? which embed applet in itself. try that one pleasei am using eclipseregardsAniruddha
Aniruddha-Herea at 2007-7-12 19:57:24 > top of Java-index,Desktop,Core GUI APIs...