Using swing applet in IE
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.
Similar Messages
-
Using Swing applet to write data to file on SERVER
Hello,
I'm in the process of writing an applet using Swing (SDK v1.4.2). Here's the deal. The JApplet calls a JPanel, which will be used by customers on my site to enter data. I'm adding a <Save> button to the "form" which is supposed to write data to a file on the server (in order to preserve the customer's preferences).
Please note that I am NOT attempting to write data to the customer's hard disk. That requires digital certificates, etc. which I am trying to avoid for now.
Instead, I am using the URL class to access the file:
URL page = new URL("http://www.whatever.com/mycustomers/preferences.txt")
I then use the URLConnection class to establish the connection:
URLConnection conn = this.page.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
etc...
I've created a text file (preferences.txt) on my web site. Using the classes InputStreamReader, BufferedStreamReader, and StringBuffer, I can successfully read the file into a JOptionPane in my applet.
The problem comes when I try to write data TO this file. I know the file exists because the applet can read it. I've set the permissions on the file to 666. I've got all of the appropriate syntax within a try statment that catches an IOException. I also have JOptionPanes all over the place to let me know where the program is. I've tried different combinations of output streams like BufferedWriter, BufferedOutputStream, StringWriter, but the file does not get updated. When the applet runs, it does not throw any exceptions, not even when I change the URL from "HTTP://www.whatever.com/prefs.txt" to "HTTP:/www.whatever.com/prefs.txt" (only one slash on HTTP, shouldn't I get a MalformedURLException?)
I apologize for all the background, but I thought you might need it. The bottom line is:
1) Can an applet write to a file on a remote server (not local hard disk)?
2) If so, what (if any) caveats are there?
3) Is there a way to check for file existence or be able to create a new file?
4) I'm using the HTTP protocol - is there some restriction that prevents an applet from writing to a file using that protocol? If so, is there a workaround?
5) Assuming that creating/writing a file using the method I've described is possible, what would be the appropriate output streams to use? (Currently, I'm using OutputStreamWriter with BufferedWriter).
I've been struggling with this for a while. Any help/suggestions would be appreciated.
Thanks
P.S. I also posted this message on the Applet development forum, but I've received no response as of yet.Http servers support PUT as a mechanism to upload data to a specified URL. Get on the other hand which is what most people are familiar with is how you retrieve that data. The basic URLConnection is an abstraction of the Http connection which can be used for GET and POST operations by default based on doInput(true|false).. If you which to use any of the http methods other than GET|POST you will have to cast the URLConnection to HttpURLConnection so you can gain access to the specific Http functionaility that could not be abstracted.
Since you are using a hosting service the chances are that you won't be able to use HTTP PUT on their server. Most servers do not support HTTP PUT without configuring them todo so. Now Apache allows localized config through the .htacess file. It might be possible (keep in mind I am not an apache expert) to configure a particular directory to allow HTTP PUT using this .htacess file it may not be possible. You will have to consult the Apache web server documentation for that answer.
But regardless you can use the HttpURLConnection and the PUT method to send data from your applet to the server. In fact that is the preferred way to do this. If you can not configure your web server to support that method then you will have to develop a Servlet to do it. A servlet has several methods such as doGet(), doPost(), and doPut(). You would override the doPut() method get the URI path create a file and a FileOutputStream to that file, get from the request the inputstream, possibly skip the http headers, and then write byte for byte the incoming data to your OutputStream until you reach the end at which point you would close the OutputStream and send an Http Response of some sort. Typically in HTTP it would be 200 OK plus some web content. You content can be empty so long as your applet recognizes that is what it should expect...
And away you go... -
Cannot use SWING Applets!
I tried to use Netscape 6.2 Browser with "Java(TM) Plug-in: Version 1.4.0" to start an swing applet. but what i got was an error in the java-Console. In the dokumentation i counld not find a hint to solve the problem.
java-Consol error message:
java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(Unknown Source)
at sun.net.www.protocol.file.Handler.openConnection(Unknown Source)
at sun.plugin.net.protocol.file.Handler.openConnection(Unknown Source)
at java.net.URL.openConnection(Unknown Source)
at sun.applet.AppletPanel.getAccessControlContext(Unknown Source)
at sun.applet.AppletPanel.getClassLoader(Unknown Source)
at sun.applet.AppletPanel.createAppletThread(Unknown Source)
at sun.applet.AppletPanel.init(Unknown Source)
at sun.plugin.AppletViewer.appletInit(Unknown Source)
at sun.plugin.viewer.LifeCycleManager.initAppletPanel(Unknown Source)
at sun.plugin.viewer.WNetscapePluginObject$Initer.run(Unknown Source)
HTML File for applet start:
<!-- The following code is specified at the beginning of the <BODY> tag. -->
<SCRIPT LANGUAGE="JavaScript"><!--
var info = navigator.userAgent; var ns = false;
var ie = (info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0
&& _info.indexOf("Windows 3.1") < 0);
//--></SCRIPT>
<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
var _ns = (navigator.appName.indexOf("Netscape") >= 0
&& ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0
&& java.lang.System.getProperty("os.version").indexOf("3.5") < 0)
|| _info.indexOf("Sun") > 0));
//--></SCRIPT></COMMENT>
<!-- The following code is repeated for each APPLET tag -->
<SCRIPT LANGUAGE="JavaScript"><!--
if (_ie == true) document.writeln('
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200" align="baseline"
codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#Version=1,4,0,mn">
<NOEMBED><XMP>');
else if (_ns == true) document.writeln('
<EMBED
type="application/x-java-applet;jpi-version=1.4" width="200" height="200"
align="baseline" code="swingtest.swingtest.class" codebase="html/"
model="models/HyaluronicAcid.xyz"
pluginspage="http://java.sun.com/products/plugin/1.4/plugin-install.html">
<NOEMBED><XMP>');
//--></SCRIPT>
<APPLET code="swingtest.swingtest.class" codebase="html/" align="baseline"
width="200" height="200">
</XMP>
<PARAM NAME="java_code" VALUE="swingtest.swingtest.class">
<PARAM NAME="java_codebase" VALUE="html/">
<PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.4">
<PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
<PARAM NAME="scriptable" VALUE="true">
No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
</APPLET></NOEMBED></EMBED>
</OBJECT>
<!--
<APPLET code="swingtest.swingtest.class" codebase="html/" align="baseline"
width="200" height="200">
<PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
</APPLET>
-->Use the search bar to the left and you will find many things...
Follow the link in the post below:
http://forum.java.sun.com/thread.jspa?threadID=483984&messageID=2567249 -
Desperately seeking help!! IE Crashes using Swing Applet
Hi,
I've created a grid applet using JTable and Swing in an applet. It runs great with data from a SQL database. I have at least 3 instances of the grid on the same page and other places on the site.
However, Internet Explorer crashes frequently throwing an error "Unhandled exception at xxxxxxx in IExplore.exe (Beans.ocx).
And the behavior is random and unpredictable.
I've been desperately trying to look for help to fix this.
Could someone please, please offer some suggestion?
Thanks in advance,
Anand.I agree. Try upgrading your plug-in version to 1.3.1. Keep in mind though that after 1.3.0, Sun changed where the plug-in looks for the root certificate. If you're using a Verisign or Thawte certificate, you shouldn't have any problems. If you're using your own certificate, you'll probably need to import it into the cacerts file in the lib/security directory under the installation directory of your jre.
Hope this helps,
Mark -
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. -
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. -
Swing Applet - Internet Explorer - Focus issue - tool tips
Hi ,
We are using Swing applet in IE Browser , except this swing component rest of the components in the browser are HTML/DHTML components.
and we are having issue focus issue with this swing components ,
once immediately after launching the swing applet , the UI components are having some focus issue , if I bring the mouse on top of the swing UI components , we couldn't able to see the tooltips(flyover text) of those Swing UI components.
However if we click some where on the Swing applet frame , we are able to see these tooltips(flyover text) .
It looks like a kind of compatibility issue between swing and IE browser .
I am trying to find a solution for this issue , so that once after launching the applet , tooltips will work without need to click on the applet bar.
Can somebody share some thoughts on this issue??
Thanks,
Bonthu.As a wild guess you are mixing Swing and awt components which is a big no-no and among other things can cause repainting, refreshing issues.
If you want more help then that you need to post some code that shows us what you are doing. -
I'm using swing applet.My applet is getting flickering only when i embed it in html
I heard that,swing 'll handle flickering on its own.But i see it in appeltviewer it okie..My
panel's size is also very big its,17040 pixel...what should i have to do avoid flickeringMy crystalball tells me that you are painting the entire screen with each call to paint and your are also making a call to super.paintComponent(g) when you do so... hence much flickering exists with your application even though it's double buffered.
To avoid this problem do the following:
take 3 whole slottered chickens, put them in a bag and ... oh that was for array problems... let me see for flickering....
Well, you need to do offscreen rendering to an image and call repaint when done, but in your paintComponent(Graphics g) do this:
public void paintComponent(Graphics g){
drawImage(myOffscreenImage4Rendering, 0, 0, this); //notice 1 liner--no other code needed or wanted here.
}I do this with 1600x1200 on an AMD 2GHz with 500+ objects being drawn and no flicker. I've had up to 10,000 objects with no flicker, but yes, the animation speed was severely impacted due to the number of objects being rendered each cycle. -
I can't use swing components in my applets
When I write an applet without any swing components, my browser never has any trouble finding the classes it needs, whether they're classes I've written or classes that came with Java. However, when I try to use swing components it cannot find them, because it is looking in the wrong place:
On my computer I have a directory called C:\Java, into which I installed my Java Development Kit (so Sun's classes are stored in the default location within that directory, wherever that is), and I store my classes in C:\Java\Files\[path depends on package]. My browser gives an error message along the lines of "Cannot find class JFrame at C:\Java\Files\javax\swing\JFrame.class"; it shouldn't be looking for this non-existent directory, it should find the swing components where it finds, for example, the Applet class and the Graphics class.
Is there any way I can set the classpath on my browser? Are the swing components stored separately from other classes (I'm using the J2SE v1.3)?
Thanks in advance.Without having complete information, it appears that you are running your applets using the browser's VM. Further, I assume you are using either IE or Netscape Navigator pre-v6. In that case, your browser only supports Java 1.1, and Swing was implemented in Java 1.2. You need to use the Java plug-in in order to use the Swing classes (see the Plug-in forum for more information), or else download the Swing classes from Sun and include them in your CLASSPATH.
HTH,
Carl Rapson -
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);
} -
How to use mousedown applet function in swing?
hai,
i need to use the applet mousedown function in swing..
is there any way to use it or any other alternative is available for this?
if can provide me a sample code.>
i need to use the applet mousedown function in swing..>There is no such class as 'applet' in the JRE, Swing has an upper case 1st letter, functions in Java are generally referred to as methods, and there is no 'mousedown' method in the JRE.
OTOH a Swing JApplet inherits the mouseDown method from Component, and it was deprecated in Java 1.1. The documentation (JavaDocs) provides instructions on what to use instead.
>
is there any way to use it or any other alternative is available for this?
if can provide me a sample code.>If can provide me cash. Short of that, you might actually need to do some research/coding of your own.
As an aside. What does any of this have to do with Java 2D? -
Which command i use to run SWING APPLET
Hi friends,
i m a new in swing technology i got and problem when i run swing applet .
i make a file and complie it with -deprecation it work and make a .class file but how can i run this applet [i use jview command , appletviewer command but it can't work]
i hope that someone hellp me.Just as a matter of interest and i know its a stupid question, but did you create a html file to access the class file/jar
Here is some example code of an applet html page
Hope it helps...
Also have you put it in a Jar file?
<html>
<head>
<title>(Whatever title youu want)</title>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">
<TR>
<APPLET CODE = "ClassName.class" ARCHIVE = "JarName.jar" WIDTH = "800" HEIGHT = "600"></XMP>
<PARAM NAME = CODE VALUE = "ClassName.class" >
<PARAM NAME = ARCHIVE VALUE = "JarName.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<dont worry about this>(they just variables for my applet)
<PARAM NAME = SERVER_IP VALUE ="192.1.1.209">
<PARAM NAME = SERVER_PORT VALUE =8701>
<PARAM NAME = DEBUG VALUE =true>
<PARAM NAME = REFRESH VALUE =10000>
<PARAM NAME = TAIL_REFRESH VALUE =2500>
<PARAM NAME = MESSAGE_TIMEOUT VALUE =60>
</dont worry about this>
</APPLET>
</body>
</html> -
Shall i use Swing or AWT for creating a chessboard applet??
Hi,
I need to build an applet which should dislpay a chessboard where i should
be able to move the pieces around, read in a game analysis, etc...
I am a beginner and i would like some advice on if i should use swing or awt?
Which one is it easier to work with in terms of dispaying the pieces, moving the pieces and achieving other more challenging functionalities?
Is it good idea to mix both of them? i.e have a japplet and use a canvas for displaying the board??
Any advice would be much obliged.I used to think AWT
And someone told me Swing was better..and that all of the Drag-n-Drop stuff doesn't work well with AWT.
I have to admit that I used AWT up until a project about 3 months ago--I liked it better, but Swing does seem to have more builtins for handling the things you would need to for the Chess Board. Not that you CAN'T do them with AWT, but that they are harder to do with AWT.
As far as reading in game analysis, etc..that really is independent of Swing/AWT -
Swing Applet using JSObject.getWindow can not use javaFX
I have a Swing Applet that I will like to extend with some javaFX 2.0.3 abilities.
The Swing Applet uses the JSObject.getWindow method which is part of plugin.jar.
When I add javaFX I am not able to compile my application as jfxrt.jar also has a JSObject implementation, but without the getWindow method.
Is there any way I can extend my existing applet with javaFX?The order of dependencies is probably not the issue here but rather that there are two classes with the same fully qualified name which causes problems if the signatures differ
-
How use system.out.println with a Java Swing Applet?
Hi guys,
I was just wondering what can I use to view output on the Java console with a Java Swing Applet?
At the moment I'm using a JTextArea within the Applet for debugging but I want output to appear in the browser java console but system.out.println doesn't work.
I'm viewing the Swing Applet on Netscape 4.7 browser.
Any ideas?System.out.println()s work fine! I'm guessing that your problem is that you are looking at the wrong console window!
You're using the Java Plug-in, right? On Windows, go to your Control Panel and double click "Java Plug-in". You should find a checkbox option to "Show Java Console" - make sure this is checked. Next time you fire up you JApplet, you should see a Java Console window popup.
Hope this helps!
Maybe you are looking for
-
OTM: OpenScript fail due to
Hi, When I run an OpenScript in OTM it fails even though it runs fine in OOS. OTM gets as far as logging into PeopleSoft, but no further. The script was created using FT-Oracle EBS/Forms. According to the ResultsReport: Object not found: /web:window[
-
Multiple crashes within certain apps.
Recently, i started to suspect my computer had gotten malware. I took the steps nessicary to remove it. Check for updates. Downloaded 2 different anti-virus software. Quarentine and delete/clean infected files. The suspicion started when i found my
-
How to read a very BIG XML-File
Hello together, how can I read a XML file of e.g. 2 GByte in ABAP ( Release 4.6C ). The file should be read from the Application-Server ( not from the Front-End ). Problem: Too much MEMORY is needed by the upload of the complete file into an internal
-
Pictures in PDF Forms (Adobe Acrobat Pro 9)
Hello everyone, I have a situation where I need two drop downs determine which picture to display. I have been reading on this topic and see that the best solution (that I have come across) would be to make a button into a picture and toggle the vis
-
Goods Issue Internal Order using MIGO
Dear All, I want to do Goods Issue Internal Order using MIGO, but then an error message popup says "Order xxx not found or not permitted for goods movement" When i do the Goods Issue using MB1A, the transaction run well, So why MIGO transaction canno