Draw in an applet and use the Standalone to view it....

Hi,

I created an applet with the JDeveloper tutorial. I chose to have the standart methods, and the standalone (which creates a main so I can see what I'm doing).

This code does not have a paint method.

The problem is that, for example, when I set a backgroud color in the property inspector, it doesnt take effect. Do I need to have a paint method? Is the standalone the best way to see how is the applet? Is there a better way to watch my applet? I tried to oppen the applet viewer but the window closes inmediately, so I don't have a chance to write any commands in it...

[601 byte] By [kandua] at [2007-11-27 8:12:05]
# 1

No idea what the "standalone" is.

Why don't you start with something really really simple:

import java.awt.*;

import javax.swing.text.*;

import javax.swing.*;

public class AppletTest extends JApplet

{

public void init()

{

JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

buttonPanel.add( new JButton("Button1") );

buttonPanel.add( new JButton("Button2") );

getContentPane().add(buttonPanel, BorderLayout.NORTH);

getContentPane().add( new JTextArea() );

getContentPane().add(new JButton(new DefaultEditorKit.CopyAction()), BorderLayout.SOUTH);

}

}

camickra at 2007-7-12 19:56:22 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thank you Camickr,

I'll try what you said. When I say standalone, I refer to an option that the Applet Wizard of the JDeveloper offers when you create an applet.

If I choose "can run standalone", then the applet comes with a main, so I can run the project and see how it's looking.

If you have any other suggestions so I could watch my applet, I would really appreciate it.

Thanks!

kandua at 2007-7-12 19:56:22 > top of Java-index,Desktop,Core GUI APIs...
# 3
Camickr, I can't run your code because it has an error. It says:"Costructor JButton (...) not found in class javax.swing.JButton."So I'm not generating the .class file. So when I created my html page, it just doesn't run...
kandua at 2007-7-12 19:56:22 > top of Java-index,Desktop,Core GUI APIs...
# 4

> Costructor JButton (...) not found in class javax.swing.JButton."

Well you must be using a really old version of Java. All its trying to do is create a JButton from an Action and that constructor has been around for as long as I can remember.

You can always just delete the line of code. Its not important. Its only a simple example to show how easy it is to build a GUI. The program doesn't do anything since no listeners have been added to any button.

camickra at 2007-7-12 19:56:22 > top of Java-index,Desktop,Core GUI APIs...