Displaying Swing Applets
Hey I am unable to dispay my JApplet in any browser
an error message" Load class not found is displayed in IE& Class already loaded is displayed in Netscape" but my Japplet is working fine with applet viewer
Any gurus out there to solve this problem
Thanks in advance
Neti
Special quotations have to included in your html file for the applet to be displayed in IE.
There is a tool called HTMLConverter which you can download from the java.sun.com website.
Here is the sample code required, if u can write it yourself:
<HTML>
<HEAD>Applet Examples
</HEAD>
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 200 HEIGHT = 200 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = "Ovals.class" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" CODE = "Ovals.class" WIDTH = 200 HEIGHT = 200 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!--
<APPLET CODE = "Ovals.class" WIDTH = 200 HEIGHT = 200>
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
</HTML>
Similar Messages
-
Unable to download images in a swing applet (1.3.1) behind proxy
Hi
One of my client have a proxy server and firewall and when they try to access my webserver
then all the AWT applet are downloaded and rendered on client properly. However, the swing applet written
using JDK 1.3.1 is downloaded and rendered but it doesn't display anything properly as images
are not down loaded. I have used media tracker to add images to it like oMediaTracker.addImage( oImage, index );
and then oMediaTracker.waitForAll();
Java console display at client looks as follows:
Java(TM) Plug-in: Version 1.3.1
Using JRE version 1.3.1 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\toy
Proxy Configuration: no proxy
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
q: hide console
s: dump system properties
t: dump thread list
x: clear classloader cache
0-5: set trace level to <n>
Applet Initialization start...
Applet Image Initialization start...
Trace level set to 5: basic, net, security, ext, liveconnect ... completed.
Opening http:MyServer/24/x.gif
Connecting http:MyServer/24/x.gif with no proxy
Connecting
http:MyServer/24/x.gif with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
-1149265879"
Opening http:MyServer/40/y.gif
Connecting http:MyServer/40/y.gif with no proxy
Connecting http:MyServer/40/y.gif with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
-1149265879"
Opening http://MyServer/sun/beans/infos/PanelBeanInfo.class
Connecting http://MyServer/sun/beans/infos/PanelBeanInfo.class with no proxy
Connecting http://MyServer/sun/beans/infos/PanelBeanInfo.class with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
-1149265879"
Opening http://MyServer/java/awt/ContainerBeanInfo.class
Connecting http://MyServer/java/awt/ContainerBeanInfo.class with no proxy
Connecting http://MyServer/java/awt/ContainerBeanInfo.class
Client machine tries to access these images but i never receive a call at web server end when i see
IIS log.
CLient environment:
-Windows 2000/XP/NT
-Internet explorer 6.0 SP1 or IE 5.5 SP2
with connection->LAN Setting->Use Automatic configuration script(only checked)
-Java Plugin configured like proxies->Use Browser Setting
-JDK 1.3.1 plug in at client(downloaded and Installed automatically on demand)
-Object tag used to download applet and plugin
-Firewall and proxy(i don't know about vendor)
My webserver environment
Windows 2000/iis 5.0 with anonymous authentication and
cache-control header set to no-store (so that proxy doesn't cache anything)
QUESTIONS:
~~~~~~~~~
Q.1. When i try from home network that has a proxy then everything works fine. At client site everything except
image download works fine. I mean jars are downloaded and i can see anything drawn using JAVA API.
When i try from home i see following java console trace
Java(TM) Plug-in: Version 1.3.1
Using JRE version 1.3.1 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\wuko
Proxy Configuration: Automatic Proxy Configuration
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
q: hide console
s: dump system properties
t: dump thread list
x: clear classloader cache
0-5: set trace level to <n>
Trace level set to 5: basic, net, security, ext, liveconnect ... completed.
Applet Initialization start...
Applet Image Initialization start...
Opening http://MyServer/24/connec.gif
Connecting http://MyServer/24/connec.gif with proxy=197.168.1.100:808
Connecting http://MyServer/24/connec.gif with cookie "ASPSESSIONIDQQGQQCYU=GBJFAOABCJFPDMGFHEKLDACA; JSESSIONID=26yu5m1b4upVuXoAoDmtMbWXQmetQpyzqjFANszo9vFubujT4qGX!-1149265879"
Opening http://MyServer/24/cool.gif
Connecting http://MyServer/24/cool.gif with proxy=197.168.1.100:808
Connecting http://MyServer/24/cool.gif with cookie "ASPSESSIONIDQQGQQCYU=GBJFAOABCJFPDMGFHEKLDACA; JSESSIONID=26yu5m1b4upVuXoAoDmtMbWXQmetQpyzqjFANszo9vFubujT4qGX!-1149265879"
etc
I can't set the plugin at client to use automatic script just like IE browser uses. This option is not supported in JRE1.3.1. Looks to be supported in JRE1.4.1. My client doesn't want to set manual proxy ip and port in plugin as they don't want to reveal this info to everyone within the company for security reason.
Q.2. Why some classes like PanelBeanInfo.class, JAppletBeanInfo.class are downloaded
from my server while it doesn't exist at my webserver. Any thing stupid IE or plugin doing
at client. Any Idea?
Thanks in advance for any help.
RatanThanks to Mike and other friends who already replied on this topic.
Here is my research analysis:
Answer to Question 1:
~~~~~~~~~~~~~~~~~~~~~
The solution is to bundle all the images with JAR. Bundle with jar whichever needs it. However, it might require duplicacy.
Image img = null;
try
img = Toolkit.getDefaultToolkit().getImage(getClass().getResource(fileName));
catch (Exception e) { }
In this case make sure that you have image at the same location where you access it. For example if you have to access an image in package class com.awt.ui.MyClass then your image should also be at location ..\com\awt\ui
Note: It will require image duplicacy in your JAR but it solves the problem. It gives the advantage of fewer download from server.
Answer to Question 2:
~~~~~~~~~~~~~~~~~~~~~
IE treats applet as an active-X and try to look for these classes in your JAR. SUN has stopped its support in JDK1.3.1 and plus. What one can do is to create dummy classes with these names and bundle it with your JAR. You have to create these dummy classes if you enable Basic authentication on your web server then browser will try to look for these classes on the server and continue to prompt you for login and password. It might bother your customer un-necessarily to enter login and password too many times prompted by plug-in (plug in).
--Ratan -
PDF document in a Swing Applet?
How can you display a PDF document in a Swing Applet?
I have implemented a document archiving solution that provides a Swing UI to search a database for available documents. All the documents in the archive are in the PDF format. To accomplish this I use an html frameset where a Swing applet is displayed in one frame and the PDF document is displayed in the lower frame. I use LiveConnect to have my javascript communicate with the applet. My applet calls a javascript function that causes the URL of the lower frame point to the PDF document. This works fine, but I would rather use an all Java UI instead of depending on the browser and javascript.
How can we get Adobe or Sun to address this need? -
Swing Applet in JSP: problem with fetching data from database
i am facing a problem while fetching data from database using Swing Applet plugged in a JSP page.
// necessary import statements
public class NewJApplet extends javax.swing.JApplet {
private JLabel jlblNewTitle;
private Vector vec;
public static void main(String[] args) {
JFrame frame = new JFrame();
NewJApplet inst = new NewJApplet();
frame.getContentPane().add(inst);
((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
frame.pack();
frame.setVisible(true);
public NewJApplet() {
super();
initGUI();
private void initGUI() {
try {
this.setSize(542, 701);
this.getContentPane().setLayout(null);
jlblTitle = new JLabel();
this.getContentPane().add(jlblTitle);
jlblTitle.setText("TITLE");
jlblTitle.setBounds(197, 16, 117, 30);
jlblTitle.setFont(new java.awt.Font("Dialog",1,20));
jlblNewTitle = new JLabel();
this.getContentPane().add(jlblNewTitle);
Vector vecTemp = getDBDatum(); // data fetched fm DB r stored here.
jlblNewTitle.setText(vecTemp.get(1).toString());
jlblNewTitle.setBounds(350, 16, 117, 30);
jlblNewTitle.setFont(new java.awt.Font("Dialog",1,20));
} catch (Exception e) {
e.printStackTrace();
}//end of initGUI()
private Vector getDBDatum() {
// fetches datum from oracle database and stores it in a vector
return lvecData;
}//end of getDBDatum()
}//end of class
in index.jsp page i have included the following code for calling this applet:
<jsp:plugin type="applet" code="NewJApplet.class" codebase="applets"
width="600" height="300">
<jsp:fallback>Could not load applet...</jsp:fallback>
</jsp:plugin>
if i view it in using AppletViewer it runs perfectly and display the data in JLabel. (ie, both jlblTitle and jlblNewTitle).(ie, DATA FETCHES FROM db AND DISPLAYS PROPERLY)
BUT IF I CLICK ON INDEX.JSP, ONLY jlblTitle APPEARS. jlblnNewTitle WILL BE BLANK(this label name is supposed to fetch from database)
EVERY THING IS DISPAYING PROPERLY EXCEPT DATA FROM DATABASE!!!
i signed the applet as follows :
grant {
permission java.security.AllPermission;
Can any body help me to figure out the problem?This is the Swing Applet java code
import java.awt.Dimension;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JScrollPane;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
public class HaiApplet extends javax.swing.JApplet {
private JLabel jlblTitle;
private JLabel jlblNewTitle;
private Vector vec;
* main method to display this
* JApplet inside a new JFrame.
public static void main(String[] args) {
JFrame frame = new JFrame();
NewJApplet inst = new NewJApplet();
frame.getContentPane().add(inst);
((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
frame.pack();
frame.setVisible(true);
public HaiApplet() {
super();
initGUI();
private void initGUI() {
try {
this.setSize(542, 701);
this.getContentPane().setLayout(null);
jlblTitle = new JLabel();
this.getContentPane().add(jlblTitle);
jlblTitle.setText("OMMS");
jlblTitle.setBounds(197, 16, 117, 30);
jlblTitle.setFont(new java.awt.Font("Dialog",1,20));
jlblTitle.setHorizontalAlignment(SwingConstants.CENTER);
jlblTitle.setForeground(new java.awt.Color(0,128,192));
jlblNewTitle = new JLabel();
this.getContentPane().add(jlblNewTitle);
Vector vecTemp = getDBDatum();
jlblNewTitle.setText(vecTemp.get(1).toString());
jlblNewTitle.setBounds(350, 16, 117, 30);
jlblNewTitle.setFont(new java.awt.Font("Dialog",1,20));
} catch (Exception e) {
e.printStackTrace();
}//end of initGUI()
private Vector getDBDatum() {
Vector lvecData = new Vector(10,5);
Connection lcon = null;
Statement lstmt = null;
ResultSet lrsResults = null;
String lstrSQL = null;
String lstrOut = null;
try {
OmmsDBConnect db = new OmmsDBConnect();
lcon = db.connectDb();
lstmt = lcon.createStatement(lrsResults.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
lstrSQL = "select DT_ID from P_DATATABLES";
lrsResults = lstmt.executeQuery(lstrSQL);
int i = 0;
lrsResults.last();
int length = lrsResults.getRow();
System.out.println(length);
lrsResults.beforeFirst();
int recCount = 0;
while (lrsResults.next()) {
recCount++;
lvecData.addElement(new String(lrsResults.getString("DT_ID")));
// System.out.println("ID : " + lrsResults.getString(1));
i++;
}System.out.println("here 3 out fm while");
catch(SQLException e) {
System.out.print("SQLException: ");
System.out.println(e.getMessage());
catch(Exception ex) {
lstrOut = "Exception Occured " + ex.getMessage();
finally {
try {
lrsResults.close();
lstmt.close();
lcon.close();
System.out.println("[DONE]");
catch(Exception e) {
System.out.println(e);
}//end of finally
return lvecData;
}//end of getDBDatum()
}//end of classOfcourse the above code compiles and runs well. in Applet Viewer
I plugged the above Swing Applet in a JSP page index.jsp
<jsp:plugin type="applet" code="NewJApplet.class" codebase="applets"
width="600" height="300">
<jsp:fallback>Could not load applet...</jsp:fallback>
</jsp:plugin>Every thing is working fine in AppletViewer...But if i view this in any browser, then only the jlblTitle is displaying. jlblNewTitle is not displaying(this label name is actually fetching from thedatabase)
can any body help me regarding this matter.? Thx in Advance. -
Hai Friends,
I am using jdk1.3.1 and all my applications using JSwing run well. But if i make an applet using Swing, it could be compiled well, but my browser IE5.5 does not run my Swing Applet, instead it displays javax.swing.JApplet not found. I don't know how to make my Swing Applet work.
Please kindly help me. Thank u.Well, have you converted your html, with applet tag, with Java Plug-in HTML Converter? If not, you should try. You can download it from sun's web site.
lala -
I have 2 simple swing applets running simultaneously. When I refresh the browser window in which one of them has been launched from, I get the following error:
java.lang.NullPointerException
at sun.java2d.SunGraphics2D.<init>(SunGraphics2D.java:211)
Any ideas? I'm testing with IE 6.0, JRE 1.4.0_02
I'm assuming that the problem is thread related, but can't seem to resolve the problem.Thanks for the help, but I'm still having problems.
I've trimmed the code down even more, and still have the same problem. It works fine as long as I have one instance of the applet running at once. Here's the HTML/Javascript that I'm using to launch the two instances.
Another weird behavior is that the applet that I'm popping up in exploitationFrame.html has no problems when I refresh. Only the applet which is displayed in the main browser has problems.
launcher.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT>
function popUp(location, xsize, ysize) {
window.open(location,"applet","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=" + xsize + ",height=" + ysize);
</SCRIPT>
</HEAD>
<BODY>
<applet code="ExploitationProto" codebase="WEB-INF/classes/" width="100" height="300">
</applet>
Launch new window
</BODY>
</HTML>
exploitationFrame.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<applet code="ExploitationProto" codebase="WEB-INF/classes/" width="100" height="100">
</applet>
</BODY>
</HTML>
Exploitation.java
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class ExploitationProto extends Applet {
public void init() {
public void start()
Component contents = createComponents();
this.add(contents);
public void stop() {
public Component createComponents() {
//Create the nodes.
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Test");
createNodes(top);
//Create a tree that allows one selection at a time.
final JTree tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
JScrollPane treeView = new JScrollPane(tree);
Dimension minimumSize = new Dimension(100, 200);
treeView.setPreferredSize(minimumSize);
JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
pane.setLayout(new GridLayout(0, 1));
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
pane.setLayout(gridbag);
c.anchor = GridBagConstraints.NORTH;
c.gridx = 0;
c.gridy = 0;
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(treeView, c);
pane.add(treeView);
return pane;
//Set tree up
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode category = null;
DefaultMutableTreeNode node = null;
category = new DefaultMutableTreeNode("Images");
top.add(category);
node = new DefaultMutableTreeNode("image1");
category.add(node);
node = new DefaultMutableTreeNode("image2");
category.add(node);
category = new DefaultMutableTreeNode("Vector Data");
top.add(category);
node = new DefaultMutableTreeNode("vector1");
category.add(node); -
How to import and display an applet from JSP
i m using netbeans 5.0
i have class named myapplet.class
and jsp named myjsp.jsp
now i want to access(import) this myapplet.class from jsp
also i want to display this applet from this jsp
i am able to do either thing but not both
so please help me it is so urgent and important for me bcoz
i have to complete my project as early as possible
Thanks in advancemy jsp source file page path is D:\Reliance
project\WebApplication3\web\
and classes path is D:\Reliance
project\WebApplication3\build\web\WEB-INF\classes\
so problem is that if i want to use myapplet.class
then i have to put my class in D:\Reliance
project\WebApplication3\build\web\WEB-INF\classes\
location
but at that time i am not able to display this applet
on my jsp
if i put my myapplet.class in
D:\Reliance project\WebApplication3\web\ then i m
able to display
applet but not able to access(import) this class
hope you will got the problem!!!
thanks for your reply !!!try to set the path of your applet on jsp something like this
"WEB-INF/classes/myclass.class" -
How to run swing applets in a browser??
I understand it is a typical question and there lot of articles on it. I tried but am confused. I installed JRE1.3 which has java plug-in along with it which supports swing applets in a browser.Once i got that plug in i also downloaded html converter but am confused how should i run my swing applet.Can anyone please explain in simple steps as to how to achieve this objective..Thanks much in advance..an example would be of real big help
ThanksThe below links will help you.
http://java.sun.com/products/plugin//1.3/docs/index.docs.html
http://java.sun.com/products/plugin/1.3/plugin.faq.html -
Best IDE and how-to create HTML for a swing Applet
Can you help me out? I've been using, and teaching with the old Symantec VisualCafe product from long, long, ago. It still works fine & I can even use it to build JFC/Swing Applets etc. But a few things have occurred. For one, a way back, Symantec sold VisualCafe to WEBGAIN - who now has gone out of business and sold it to a company called TOGETHERSOFT - who doesn't support it any longer.
This isn't really a big deal to me, because I can still build and deploy applets that are pre-swing easily enough. (as can my students)
HOWEVER... I'd like to be running with the LATEST Java (I think it's 1.4.01) and I'd LIKE to use whatever is the best development environment I can use - especially one I can recommend to my students. Do you know what that should be?
What's more, I'd still like to take some JFC/Swing created applets (even if compiled with the older VisualCafe IDE) and generate the HTML to allow 1.4 enabled browsers to run them (this is the case for the schools versions of Explorer and Netscape). Now, the HTML I have INSTALLED for the students used the HTML converter - back in 1.2 to produce the HTML at the bottom of this. This code no longer works now with current browsers. Do you know HOW one makes a jfc/swing compiled applet run on the latest browsers?
Any help or direction you can give would be appreciated.
thanks,
Bobby Berns
[email protected]
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 756 HEIGHT = 396 codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0">
<PARAM NAME = CODE VALUE = "lottery.class" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.2" java_CODE = "lottery.class" WIDTH = 756 HEIGHT = 396 pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"><NOEMBED></COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!--
<APPLET CODE = "lottery.class" WIDTH = 756 HEIGHT = 396 >
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->Bobby,
It's been a while since I've used the HTML Converter, but if I had to guess I'd say you need a newer version than what you have. Also, doesn't the converter allow you to choose which JDK you want to use (in which case you could select 1.4)? Again it's been a while so bear with me. Another option would be to put all the Swing classes into a .jar file (typically called swingall.jar) on your server and include that file as an attribute in your applet tag like this:
<APPLET CODE="yourApplet.class" ARCHIVE="swingall.jar">
This way you don't have to use the Java Plug-in, however the initial download time of the .jar file can be significant.
As for an IDE, I've always been happy using a text editor like UltraEdit. However, I've heard good things about Forte, and hey, it's free!
Regarding Christina's post, that solution will only work if the Applet does not use Swing components (and Bobby specifically said it does). By using the <OBJECT> and <EMBED> tags, rather than the <APPLET> tag, you force the browser to use the Java Plug-in (rather than the browser's default JVM).
Hope that helps,
- Sheepy -
hi there,
I am a student at the University of Portsmouth in the UK in my third and last year. I am doing my dissertation as a game using applets for a client at the university of which there consits four prototypes. One of the main specification points is that it should work on an apple mac, therefore I am using Swing applets. however with my first prototype it works fine on windows in windows Explorer, firefox and Netscape but i cant get it to work on Mac os 9 or X even with the latest version of java installed on the machine. Can anyone tell me why this is so, I would be very gratefull.
As I cant post the whole applet here as a file download I will just put some code snippets of the main program classes.
Applet ------------------------------
* Class JugglingBalls - A sub class of JApplet that combines the GameInterface and GamePanel into a single application
* @author (Liam Morren)
* @version (v1.0)
import java.awt.*;
import javax.swing.*;
public class JugglingBalls extends JApplet
// instance variables -----------------------------------------------------------------------------------------------------------------------------------
private GamePanel gamePanel; // The game panel including game and render loop
private GameInterface gameInterface; // The swing interface to modify the game scene components
// JApplet methods -------------------------------------------------------------------------------------------------------------------------------------
* Called by the browser or applet viewer to inform this JApplet that it
* has been loaded into the system. It is always called before the first
* time that the start method is called.
public void init()
gamePanel = new GamePanel();
gameInterface = new GameInterface(gamePanel.getGameScene());
Container content = getContentPane(); // The container for components in the applet
setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
content.add(gamePanel);
content.add(gameInterface);
* Returns information about this applet.
* An applet should override this method to return a String containing
* information about the author, version, and copyright of the JApplet.
* @return a String representation of information about this JApplet
public String getAppletInfo()
// provide information about the applet
return "Title: JugglingBalls \nAuthor: Liam Morren \nA simple application showing balls juggling in the air.";
Interface -------------------------------------
* Class GameInterface - Lets you manipulate the game components using swing components
* @author (Liam Morren)
* @version (v1.0)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class GameInterface extends JPanel
// instance variables -------------------------------------------------------------------------------------------------------------------------------------
private GameScene gameScene; // Reference to the game scene
private JTabbedPane gameTabs; // Tabs for Game, Balls and Background
// Scene panel
JButton pause, start, reset; // Buttons
// Balls panel
JRadioButton redBall, greenBall, blueBall, archBall, figureOfEightBall; // Radio buttons
JCheckBox canSplit; // Check box
JComboBox setAllPaths, setAllTypes, newBall, selectBall; // Drop down boxes
JButton deleteBall; // Button
Ball currentBall; // Current ball being changed
// Background panel
JRadioButton black, white, red, green, blue, hide, show, stop, move, arch, figureOfEight; // Radio buttons
// Constructors -------------------------------------------------------------------------------------------------------------------------------------------
* Constructor for objects of class GameInterface
public GameInterface(GameScene gameSceneIn)
gameScene = gameSceneIn; // Reference to the game scene
gameTabs = new JTabbedPane(); // JTabbedPane to hold different toolbars
gameTabs.setPreferredSize(new Dimension(200, 494)); // Set the preffered size for the tabbed pane
currentBall = gameScene.getBall(0); // First ball
// Add the panels to the tabbed pane
gameTabs.addTab("Scene", makeScenePanel());
gameTabs.addTab("Balls", makeBallsPanel());
gameTabs.addTab("Background", makeBackgroundPanel());
add(gameTabs); // Add the tab to the game interface panel
setPreferredSize(new Dimension(200, 200));
// Other methods ------------------------------------------------------------------------------------------------------------------------------------------
* makeScenePanel
* @return JPanel - The scene panel with buttons added
private JPanel makeScenePanel()
// Make scene panel
JPanel scenePanel = new JPanel();
scenePanel.setLayout(new BoxLayout(scenePanel, BoxLayout.Y_AXIS)); // Change layout
pause = new JButton("Pause"); // Make buttons
start = new JButton("Start");
reset = new JButton("Reset");
// Add button actions
pause.addActionListener(new ActionListener() // Add button listener to pause button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.setPaused(true); // Pause game
start.addActionListener(new ActionListener() // Add button listener to start button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.setPaused(false); // Unpause game
reset.addActionListener(new ActionListener() // Add button listener to reset button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.reset(); // Reset game
updateSelectBallComboBox();
changeSelectedBall(0);
scenePanel.add(pause); // Add buttons to scene panel
scenePanel.add(start);
scenePanel.add(reset);
return scenePanel;
* makeBackgroundPanel
* @return JPanel - The background panel with buttons added
private JPanel makeBackgroundPanel()
// Make scene panel
JPanel backgroundPanel = new JPanel();
backgroundPanel.setLayout(new GridLayout(5, 1, 2, 2)); // Change layout
// Make buttons
// background colour buttons
JPanel backgroundcolour = new JPanel(); // Change backgroundcolour panel
backgroundcolour.setBorder(BorderFactory.createLineBorder(Color.black));
black = new JRadioButton("Black"); // Radio buttons to change colour
white = new JRadioButton("white");
black.setSelected(true); // Set black as already selected
ButtonGroup backColourGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
backColourGroup.add(black); // Add buttons to group
backColourGroup.add(white);
backgroundcolour.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
backgroundcolour.add(new JLabel("Background colour")); // Add label
backgroundcolour.add(black); // Add buttons to colours panel
backgroundcolour.add(white);
// Add radio button actions
black.addActionListener(new ActionListener() // Add button listener to black button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.setBackgroundColour(false); // Background colour = black
white.addActionListener(new ActionListener() // Add button listener to white button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.setBackgroundColour(true); // Background colour = white
// colour buttons
JPanel colours = new JPanel(); // Change colours panel
colours.setBorder(BorderFactory.createLineBorder(Color.black));
red = new JRadioButton("Red"); // Radio buttons to change colour
green = new JRadioButton("Green");
green.setSelected(true); // Set green as already selected
blue = new JRadioButton("Blue");
ButtonGroup colourGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
colourGroup.add(red); // Add buttons to group
colourGroup.add(green);
colourGroup.add(blue);
colours.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
colours.add(new JLabel("Change colours")); // Add label
colours.add(red); // Add buttons to colours panel
colours.add(green);
colours.add(blue);
// Add radio button actions
red.addActionListener(new ActionListener() // Add button listener to red button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (gameScene.getBackgroundEffect().getColour() != 0)
gameScene.getBackgroundEffect().setColour(0); // Background effect colour = red
green.addActionListener(new ActionListener() // Add button listener to green button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (gameScene.getBackgroundEffect().getColour() != 1)
gameScene.getBackgroundEffect().setColour(1); // Background effect colour = green
blue.addActionListener(new ActionListener() // Add button listener to blue button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (gameScene.getBackgroundEffect().getColour() != 2)
gameScene.getBackgroundEffect().setColour(2); // Background effect colour = blue
// hide buttons
JPanel hideShow = new JPanel(); // Change hideShow panel
hideShow.setBorder(BorderFactory.createLineBorder(Color.black));
hide = new JRadioButton("Hide"); // Radio buttons to hide show
show = new JRadioButton("Show");
show.setSelected(true); // Set show as already selected
ButtonGroup hideShowGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
hideShowGroup.add(hide); // Add buttons to group
hideShowGroup.add(show);
hideShow.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
hideShow.add(new JLabel("Hide / Show")); // Add label
hideShow.add(hide); // Add buttons to hideShow panel
hideShow.add(show);
// Add radio button actions
hide.addActionListener(new ActionListener() // Add button listener to hide button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().hide(); // Hide
show.addActionListener(new ActionListener() // Add button listener to show button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().unHide(); // Unhide
// stopMove buttons
JPanel stopMove = new JPanel(); // Change StopMove panel
stopMove.setBorder(BorderFactory.createLineBorder(Color.black));
stop = new JRadioButton("Stop"); // Radio buttons to stop move
move = new JRadioButton("Move");
stop.setSelected(true); // Set stop as already selected
ButtonGroup stopMoveGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
stopMoveGroup.add(stop); // Add buttons to group
stopMoveGroup.add(move);
stopMove.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
stopMove.add(new JLabel("Stop / Move")); // Add label
stopMove.add(stop); // Add buttons to stopMove panel
stopMove.add(move);
// Add radio button actions
stop.addActionListener(new ActionListener() // Add button listener to stop button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().setMove(false); // stop
move.addActionListener(new ActionListener() // Add button listener to move button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().setMove(true); // move
// changePath buttons
JPanel changePath = new JPanel(); // Change changePath panel
changePath.setBorder(BorderFactory.createLineBorder(Color.black));
arch = new JRadioButton("Arch"); // Radio buttons to change path
figureOfEight = new JRadioButton("Figure of eight");
arch.setSelected(true); // Set stop as already selected
ButtonGroup changePathGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
changePathGroup.add(arch); // Add buttons to group
changePathGroup.add(figureOfEight);
changePath.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
changePath.add(new JLabel("Change Path")); // Add label
changePath.add(arch); // Add buttons to changePath panel
changePath.add(figureOfEight);
// Add radio button actions
arch.addActionListener(new ActionListener() // Add button listener to arch button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().setPath(new Arch()); // Arch
figureOfEight.addActionListener(new ActionListener() // Add button listener to figureOfEight button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
gameScene.getBackgroundEffect().setPath(new FigureOfEight()); // Figure of eight
// Add components to background panel
backgroundPanel.add(backgroundcolour);
backgroundPanel.add(colours);
backgroundPanel.add(hideShow);
backgroundPanel.add(stopMove);
backgroundPanel.add(changePath);
return backgroundPanel;
* makeBallsPanel
* @return JPanel - The ball panel with buttons added
private JPanel makeBallsPanel()
// Make balls panel
JPanel ballsPanel = new JPanel();
ballsPanel.setLayout(new BoxLayout(ballsPanel, BoxLayout.Y_AXIS)); // Change layout
// Make buttons
// set all drop down boxes
JPanel setAll = new JPanel(); // Set all panel
setAll.setBorder(BorderFactory.createLineBorder(Color.black));
String[] setAllPathsChoices = {"Arch", "Figure of eight"}; // Selections for set all paths
setAllPaths = new JComboBox(setAllPathsChoices); // Add selections to combo box
String[] setAllTypesChoices = {"Primary ball", "Pastel ball", "3D ball", "Image ball"}; // Selections for set all types
setAllTypes = new JComboBox(setAllTypesChoices); // Add selections to combo box
setAll.add(new JLabel("Set all paths")); // Add combo boxes to set all panel
setAll.add(setAllPaths);
setAll.add(new JLabel("Set all types"));
setAll.add(setAllTypes);
// Add combo box actions
setAllPaths.addActionListener(new ActionListener() // Add selection listener to set all paths combo box
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (setAllPaths.getSelectedItem() == "Arch")
gameScene.setAllPathsArch();
else
gameScene.setAllPathsFigureOfEight();
setAllTypes.addActionListener(new ActionListener() // Add selection listener to set all types combo box
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (setAllTypes.getSelectedItem() == "Primary ball")
gameScene.setAllTypesPrimaryBall();
else if (setAllTypes.getSelectedItem() == "Pastel ball")
gameScene.setAllTypesPastelBall();
else if (setAllTypes.getSelectedItem() == "Image ball")
gameScene.setAllTypesImageBall();
else
gameScene.setAllTypesBall3D();
// new ball drop down box
JPanel newBallPanel = new JPanel(); // new ball panel
newBallPanel.setBorder(BorderFactory.createLineBorder(Color.black));
String[] newType = {"Primary ball", "Pastel ball", "3D ball", "Image ball"}; // Selections for new ball
newBall = new JComboBox(newType); // Add selections to combo box
newBallPanel.add(new JLabel("New ball")); // Add combo boxes to new ball panel
newBallPanel.add(newBall);
// Add combo box actions
newBall.addActionListener(new ActionListener() // Add selection listener to newBall combo box
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
String ballType = (String) newBall.getSelectedItem();
if (ballType == "Primary ball")
gameScene.addBall(new PrimaryBall(gameScene));
else if (ballType == "Pastel ball")
gameScene.addBall(new PastelBall(gameScene));
else if (ballType == "Image ball")
gameScene.addBall(new ImageBall(gameScene));
else
gameScene.addBall(new Ball3D(gameScene));
updateSelectBallComboBox();
changeSelectedBall(gameScene.getBalls().size() - 1); // Update interface to show new ball
// selected ball panel
JPanel selectedBallPanel = new JPanel(); // selected ball panel
selectedBallPanel.setBorder(BorderFactory.createLineBorder(Color.black));
// Select ball
selectBall = new JComboBox(gameScene.getBallList()); // Add ball list to the select drop down box
deleteBall = new JButton("DeleteBall"); // Delete button
// Ball colour
redBall = new JRadioButton("Red"); // Red choice
redBall.setSelected(true); // Start as selected
greenBall = new JRadioButton("Green"); // Green choice
blueBall = new JRadioButton("Blue"); // Blue choice
ButtonGroup ballColour = new ButtonGroup(); // So only one colour can be selected at a tim
ballColour.add(redBall);
ballColour.add(greenBall);
ballColour.add(blueBall);
// Path
archBall = new JRadioButton("Arch"); // Arch path choice
archBall.setSelected(true); // Start as selected
figureOfEightBall = new JRadioButton("Figure of eight"); // Figure of eight path choice
ButtonGroup ballPath = new ButtonGroup(); // So only one path can be selected at a tim
ballPath.add(archBall);
ballPath.add(figureOfEightBall);
// Can split
canSplit = new JCheckBox("Can split", false); // Initialy not selected
selectedBallPanel.add(new JLabel("Select ball")); // Add components to selected ball panel
selectedBallPanel.add(selectBall);
selectedBallPanel.add(deleteBall);
selectedBallPanel.add(new JLabel("Ball colour"));
selectedBallPanel.add(redBall);
selectedBallPanel.add(greenBall);
selectedBallPanel.add(blueBall);
selectedBallPanel.add(new JLabel("Path"));
selectedBallPanel.add(archBall);
selectedBallPanel.add(figureOfEightBall);
selectedBallPanel.add(canSplit);
// Add select ball drop down box action
selectBall.addActionListener(new ActionListener() // Add selection listener to selectBall combo box
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
changeSelectedBall(selectBall.getSelectedIndex()); // Change the selected ball using the index from the select ball drop down box
// Add delete button action
deleteBall.addActionListener(new ActionListener() // Add selection listener to deleteBall button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
int tempIndex = selectBall.getSelectedIndex(); // Temp index
if (gameScene.getBalls().size() > 1) // If there is more than 1 ball left
gameScene.removeBall(tempIndex); // Remove ball
updateSelectBallComboBox(); // Update with new ball list
changeSelectedBall(tempIndex - 1); // Update interface with new current selected ball
// Add radio button colour actions
redBall.addActionListener(new ActionListener() // Add button listener to redBall button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (currentBall.getColour() != 0)
currentBall.setColour(0); // currentBall colour = red
greenBall.addActionListener(new ActionListener() // Add button listener to greenBall button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
if (currentBall.getColour() != 1)
currentBall.setColour(1); // currentBall colour = green
blueBall.addActionListener(new ActionListener() // Add button listener to blueBall button
public void actionPerformed(ActionEvent ev) // Background colour = blue
if (currentBall.getColour() != 2)
currentBall.setColour(2); // currentBall colour = blue
// Add path radio button actions
archBall.addActionListener(new ActionListener() // Add button listener to arch button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
currentBall.setPath(new Arch()); // Arch
figureOfEightBall.addActionListener(new ActionListener() // Add button listener to figureOfEight button
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
currentBall.setPath(new FigureOfEight()); // Figure of eight
// Add can split check button actions
canSplit.addActionListener(new ActionListener() // Add button listener to can split
public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
currentBall.setCanGiveBirth(canSplit.isSelected()); // Ball can split if can split check button is selected
// Add components to ball panel
ballsPanel.add(setAll);
ballsPanel.add(newBallPanel);
ballsPanel.add(selectedBallPanel);
return ballsPanel;
* changeSelectedBall
* @param ballIndexIn - The numbered index of the ball in the game scene list of balls. If less than 0 then equals 0. If more than ball list size then equals last ball
public void changeSelectedBall(int ballIndexIn)
if (ballIndexIn < 0) // Make sure index is within bounds
ballIndexIn = 0;
else if (ballIndexIn >= gameScene.getBalls().size())
ballIndexIn = gameScene.getBalls().size() - 1; // Else put within bounds at either end
currentBall.highlight(false); // Unhighlight current ball
currentBall = gameScene.getBall(ballIndexIn); // Get new current ball
currentBall.highlight(true); // Highlight new current ball
// Update controls to new ball
selectBall.setSelectedIndex(ballIndexIn);
switch (currentBall.getColour()) // Update colour controls
case 0: redBall.setSelected(true); break;
case 1: greenBall.setSelected(true); break;
default: blueBall.setSelected(true); break;
if (currentBall.getPath() instanceof Arch) // If path is arch
archBall.setSelected(true); // Update controls as arch
else
figureOfEightBall.setSelected(true); // Else figure of eight
canSplit.setSelected(currentBall.canGiveBirth()); // Set if the ball can split or not
* updateSelectBallComboBox
* This method updates the combo box selection model with a new one made from the updated balls arraylist from the game scene
public void updateSelectBallComboBox()
DefaultComboBoxModel model = new DefaultComboBoxModel(gameScene.getBallList());
selectBall.setModel(model);
}Kind regards
Liam morrenhttp://docs.info.apple.com/article.html?artnum=301073
This link states Mac OS X 10.4 now supports Java 5.0. It does mention nothing about Mac OS 9 or previous version of OS X. The problem you may be facing is that your Mac is running only 1.4.2 or less. The class files compiled for Java 5.0 can't run in non 5.0 versions of the Java Virtual Machine. Java 5.0 was a major release for the Java language and thus the change in numbering (though it took a little bit for this to change).
Anyway you should confirm what version of Java you have installed on your Mac.
At a command prompt:
java -version
The above URL states that the previous 1.4.2 Java version is not uninstalled, and this could still be the preferred version to use for Java applications even after installing Java 5.0.
The URL above states there is a utility to set your apps to use Java 5.0 as the perferred Java version. Who knows maybe this is all you need to do. I hope this is the case, then it probably is an easy fix, otherwise you may need to rewrite your app in Java 1.4.2 to get it to run on your version of Mac. -
How to show a html page in a swing applet -- URGENT!!!
Hi All,
I'm trying to show a html page inside a swing applet... is it possible to do that?? if so is there any built-in classes available for that?? If anyone have some examples, plz help me with that....
Thanks,
Ragui havent tested.. but this should work. i am no expert on these either, just to give you an example.. :-)
JEditorPane ePane = new JEditorPane();
HTMLEditorKit html = new HTMLEditorKit();
ePane.setEditorKit(html);
HTMLDocument htmld = new HTMLDocument();
try{
URL url = new URL("http://hcs.harvard.edu/~undercon/");
InputStream ins = url.openStream();
ePane.setDocument(htmld);
html.read(ins,htmld, 0);
this.getContentPane().add(new JScrollPane(ePane),BorderLayout.CENTER);
catch(Exception e)
e.printStackTrace();
} -
How to use Flash buttons/animation in a Swing/Applet?
Hello,
I want to use flash button as like as JButton that we use in Swing/ Applet. How can I do So?
Please help me.
Thanks-[http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html]
Or maybe just...
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class Blinky {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run() {
URL url = null;
try {
url = new URL("http://www.gifanimations.com/GA/image/animations/bodyparts/eyes/eye-01.gif");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
JFrame f = new JFrame("Blinky");
f.getContentPane().add(new JButton(new ImageIcon(url)));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
} -
Swing applet view problem in IE
Hi,
I am new to Java and have to develop a web enabled tool where the servlets in my Solaris-Tomcat web server is manipulating with data in an oracle database. The client code is on Swing Applet, which is to be opened in Internet Explorer 5.5 from Windows NT platform.
In view of this, I have written a small swing applet and it is not opening in IE. I heard that I need to use HTML converter to run Swing applets in IE. But, Is it enough to download the HTML converter for Solaris and install it in the server and convert the html pages where <applet> tag is included? Or , do I need to install the HTML converter for windows to all the client machines?
Please help. This is very urgent.
Thanks in adance.You can use this html code :
<html>
<body>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 695 HEIGHT = 525 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = MyApplet >
<PARAM NAME = CODEBASE VALUE = "." >
<PARAM NAME = ARCHIVE VALUE = "MyApplet.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
</OBJECT>
</body>
</html>
replacing only the dimension, the code value and removing or modifying archive value.
Don't modiy the classid. This code indicates to the browser to use the Sun Java VM instead of its own vm.
I hope this helps,
Denis -
Dear,
Is there any way to use swing applet in IE.
Thanks,If you are trying to make your code workable with Microsoft's VM, then I'd say you are looking for trouble. That VM's version is 1.1.4, if I'm not mistaken.
Better stick to the JRE 1.4 with the plugin. -
Why won't my HTML page display my applet?
I can't figure this out. It works fine through Sun's appletviewer. Here is my HTML code:
<applet code="backGroundSwing.class" height=200 width=500></applet>
Here is my applet code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
//<applet code="backGroundSwing.class" height=500 width=500></applet>
public class backGroundSwing extends JApplet{
sprite pane;
JButton red = new JButton("Red");
JButton green = new JButton("Green");
JButton blue = new JButton("Blue");
JButton cyan = new JButton("Cyan");
JButton yellow = new JButton("Yellow");
JButton orange = new JButton("Orange");
public void init(){
Container contentPane = getContentPane();
pane = new sprite();
contentPane.add(pane);
pane.add(red);
pane.add(green);
pane.add(blue);
pane.add(cyan);
pane.add(yellow);
pane.add(orange);
red.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.red);
green.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.green);
blue.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.blue);
cyan.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.cyan);
yellow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.yellow);
orange.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.orange);
class sprite extends JPanel{
sprite(){No, all the other applets use AWT. I think I have the plug in. At least, on my control panel, I have an icon that says:
java 1.3.1 plug in.
Is there a way that people with out any java software installed on there computer except a java enable browser view my swing applets?
Here is my source code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
//<applet code="backGroundSwing.class" height=500 width=500></applet>
public class backGroundSwing extends JApplet{
sprite pane;
JButton red = new JButton("Red");
JButton green = new JButton("Green");
JButton blue = new JButton("Blue");
JButton cyan = new JButton("Cyan");
JButton yellow = new JButton("Yellow");
JButton orange = new JButton("Orange");
public void init(){
Container contentPane = getContentPane();
pane = new sprite();
contentPane.add(pane);
pane.add(red);
pane.add(green);
pane.add(blue);
pane.add(cyan);
pane.add(yellow);
pane.add(orange);
red.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.red);
green.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.green);
blue.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.blue);
cyan.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.cyan);
yellow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.yellow);
orange.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
pane.setBackground(Color.orange);
class sprite extends JPanel{
sprite(){
Maybe you are looking for
-
System Crash and Slow Performance
Hello - I am hoping that someone might help me -- before upgrading (or downgrading dependent of your view) I was happy and go lucky with my Power Mac G5 -- I have connected via firewire two external hard drives (1 TB) and (500 GB) along with my (2X 5
-
Regarding alv report with check boxes
Hai, i have four check boxes as input named new,rejected,accepted and all.these four four check boxes information is nothing but the information that displayed under one field in my internal table.if i click the new check box means that corresponding
-
ok i know that this may seem a bit different... but anyway here it goes... i have been in the process of making a paintball playing robot for about a year now, it is in the final stages but the only thing i need is a way to control it out on the fiel
-
Re-importing Configuration Objects
experts! I have imported Configuration Objects from .tpz files in Integration Directory. Because of those objects where unable to activate, I did a reject change and all objects were gone. When I try re-import from the same .tpz file, it is not showi
-
I've seen a couple of other posts regarding this but no answers as of yet. Stuck at BIOS/UEFI in a reboot loop. Top left shows Reset: 10Sec (and counts down). Lenovo logo and message: Security engine initialization failed. Contact your support repr