New To Java. Learning About Java Applet.
Hi all, i am new to java. Actually i am facing problem with java applet. I am trying to use my cellphone to surf web. When i open a webpage from cellphone, the part which contain the java applet, it cannot be shown and appeared blank. I am using Nokia 7610, can it be solve?
Can anybody help me? Thank You.
JSE JRE stand for Sun Java Studio Enterprise 8.1 Final Release or Java SE Runtime Environment (JRE)? Which Shall i download? By the way the file type are .exe and .sh , how to let it become .sis?
Similar Messages
-
Learn about writing applet for java smart card
hi to all i am newbie in here and need to start write applet for my project
but i am little confuse about writing applet please guide me for doing that
thank youmaybe this link how to develop new smart card application(write and read data on smart card will be useful
-
How do you begin learning about Java?
Hi. I'm new to Java. I began taking a class at the local Community college where I live. I'm in my second term. It's a lot harder than the first. I'm not sure if I still understand the basics. I've written in COBOL, RPG I,II,III&IV, C, C++, C#, Pascal, Fortran, and Basic...along with a few other languages, but I find Java the hardest one to understand and program in.
Anyone out there got any advise as to how to begin?
I still feel very lost.I am still learning myself. I have dabbled in programming since about 1976 when BASIC was available on the TRS-80 Model 1 but never did anything serious.
Start with the Java Tutorials at http://java.sun.com/docs/books/tutorial then look at other tutorials. There are some here:
<ul><li>Java Beginner Tutorial by
Srini Appikatla</li>
<ul><li>[http://www.javabeginner.com/]</li>
</ul>
</ul>
<ul><li>Java Advanced Tutorials on
ipodlot.com</li>
<ul><li>[http://www.ipodlot.com/javalearner/test/advanced.htm]</li>
</ul>
</ul>
I haven't worked through all of them but they look good so far.
Next, buy some books. I like "The Java Tutorial" Forth Edition. Yes, it is the same as the web site but it is easy to read sequencially. It doesn't cost much, used on Amazon.
Finally, actually write some code. It doesn't have to do much. Just play around. As you learn each new thing, try it out. It makes a big difference. -
Learning about Java Beans. Help!.
Hello all.
I want to learn to create and use JavaBeans, but not by where to begin.
Somebody can explain to me that it is a Java Bean and as is used.
Knows some site where it can see examples or it has a tutorial on Beans.
Thank you very much.Hi
I've just started learning Java too on my own. What I know about JavaBeans for the moment is that a JavaBean is a visual component you can create and give methods(setters and getters).
For example: JPanel, JLabel, JTextField, these are examples of JavaBeans, but you can also create them by yourself.
I use JBuilder 5 Enterprise from Borland. You can download JBuilder 6, trial version I belief from www.borland.com. I'm not certain.
How do I create JavaBeans in JBuilder?
First you have to create a new Project. Then you can go to the menu File/New and you choose to create a JavaBean. Then JBuilder asks for some information, which package, name, base class...
I've made a JavaBean, xJTextField. With each JTextField, ussually you also have a JLabel, so I've created a JavaBean xJTextField based on a JPanel. In that panel I've placed two components, a JTextField and a JLabel. I've added some methods and that's it. Now I can place an instance of xJTextField on every frame and automatically I have a JLabel and JTextField.
I have just begon too with Java, I hope I helped you a bit. If you would like it, I can send you my project with my JavaBean and some explanation.
Do you know some interesting websites about J2EE?
Rik -
What is the best way to learn about java?
What is the best and cheapest way to learn java?
I also am a Newbie to the Java language and am trying to get my head around it. I guess it all depends upon how much experience, and at what level, you have with programming in general. I have a good understanding of what my University tutor called "sequential logical thought" but I must confess this Object Oriented approach is, at first, most odd. However the Sun tutorial :
http://java.sun.com/docs/books/tutorial/java/TOC.html
: is the one I use the most. If I don't understand a specific computing term then I look it up at :
http://www.webopedia.com/
: which is a very good online encyclopedia of computing terms.
There is also :
http://www.joegrip.com/
: which is an online "interactive" tutorial (you have to pay)
I would advise against rushing out and buying a book until you have spent a whole day trolling through the 'net and seeing what it has to offer . There is a lot out there. The problem is wading through all the nonsense until you find what you're looking for.
Good luck -
Learn about Java memory spaces?
Hi, I'm a student, and I need to do some research on and write a small paper about the "three or more Java memory spaces", what they do, how they differ.
The only problem is that spending a half hour searching google and reading quite a bit of documentation, I can't find any significant reference to or classification of these memory spaces! Can anyone provide me with a link to documentation that describes these memory spaces and their uses?
Thanks for your help!Also
http://java.sun.com/products/hotspot/docs/whitepaper/Java_HotSpot_WP_Final_4_30_01.html
http://java.sun.com/developer/technicalArticles/Programming/turbo/ and the documents referenced at the end of the article
http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
Thes will lead you to additional documentation. -
I know ZIP about Java. Where Do I Learn?
I know virtually nothing about Java. I have avoided it but now I want to learn and so far everything I have seen is pretty much Greek. I have used FP2003 and Dreamweaver to build web pages but not delved ino the guts of Java. Where do I begin?
IonamicHere are some excellent resources for you:
Installation Notes - JDK 5.0 Microsoft Windows (32-bit)
Your First Cup of Java
New to Java Center
The Java� Tutorial - A practical guide for programmers
The Java� Tutorial - Trail: Learning the Java Language
Java Programming Notes - Fred Swartz
How To Think Like A Computer Scientist
Introduction to Computer Science using Java
The Java Developers Almanac 1.4
Object-Oriented Programming Concepts
Object-oriented language basics
Don't Fear the OOP
Books:
The Java Programming Language - 4th Edition
Head First Java, by Bert Bates and Kathy Sierra
Thinking in Java (Free online), by Bruce Eckel
Core Java, by Cay Horstmann and Gary Cornell
Effective Java, by Joshua Bloch
http://java.sun.com/developer/Books/javaprogramming/
Good luck, and welcome to Java!
~ -
Since I upgraded to firefox 8, I get this error window that pops up says something about java. My tabs flicker or flash, the tabs will close and open in a new window then everything stops. Then firefox does not respond. When I get this error message, I have to close all tabs wait a few seconds then open it back up it will work for a little while and then do the same thing. I have disabled plug-ins that I do not use, I have cleared my cache and cookies, I am not happy at all with this new version. I waited a while before updating. The first time I was going to update, firefox would not let me keep my anti-virus plug-in. PLEASE HELP
Hello,
The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
To Reset Firefox do the following:
#Go to Firefox > Help > Troubleshooting Information.
#Click the "Reset Firefox" button.
#Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
#Firefox will open with all factory defaults applied.
Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
Did this fix your problems? Please report back to us!
Thank you. -
I'm a new java learner from china,how should I start my journey?
I have never learned java before,how should I start it? Dose it hard to learn?
At the beginning,which part of it should I learn?
Thank you !Advice:
1. Learn the basics with simple command line applications first. Don't worry about complicated topics like Swing, databases, Web applications, etc. for at six months
2. After you learn how to write, compile & run programs with just a text editor & Java compiler, download & learn to use an Integrated Development Environment, such as Eclipse. Especially, learn how to use the debugger that comes with the IDE.
3. Experiment with lots of small programs & examples. Learn by doing (and by making mistakes).
4 Find others in your community who use Java & learn from them. -
Where to learn about the java bytecode?
I want to learn the JAVA bytecode. Where to find information about that?
The list of opcodes, list of data types, and how to use them is here:
http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html
I personally use BCEL to manipulate class files.
http://jakarta.apache.org/bcel/
Some report they prefer Soot.
http://www.sable.mcgill.ca/soot/ -
Problem converting a (working) Java program into an applet
When I'm trying to access an Image through a call to :
mediaTracker = new MediaTracker(this);
backGroundImage = getImage(getDocumentBase(), "background.gif");
mediaTracker.addImage(backGroundImage, 0);
I'm getting a nullPointerException as a result of the call to getDocumentBase() :
C:\Chantier\Java\BallsApplet
AppletViewer testBallsApplet.htmljava.lang.NullPointerException
at java.applet.Applet.getDocumentBase(Applet.java:125)
at Balls.<init>(Balls.java:84)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:296)
at java.lang.Class.newInstance(Class.java:249)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:548)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:477)
at sun.applet.AppletPanel.run(AppletPanel.java:290)
at java.lang.Thread.run(Thread.java:536)
It seems very weird to me... :-/
(all the .gif files are in the same directory than the .class files)
The problem appears with AppletViewer trying to open an HTML file
containing :
<HTML>
<APPLET CODE="Balls.class" WIDTH=300 HEIGHT=211>
</APPLET>
</HTML>
(I tried unsuccessfully the CODEBASE and ARCHIVE attributes, with and without putting the .gif and .class into a .jar file)
I can't find the solution by myself, so, I'd be very glad if someone could help
me with this... Thank you very much in advance ! :-)
You'll find below the source of a small game that I wrote and debugged (without
problem) and that I'm now (unsuccessfully) trying to convert into an Applet :
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.URL;
public class Balls extends java.applet.Applet implements Runnable, KeyListener
private Image offScreenImage;
private Image backGroundImage;
private Image[] gifImages = new Image[6];
private Image PressStart ;
private Sprite pressStartSprite = null ;
private Image YouLose ;
private Sprite YouLoseSprite = null ;
private Image NextStage ;
private Sprite NextStageSprite = null ;
private Image GamePaused ;
private Sprite GamePausedSprite = null ;
//offscreen graphics context
private Graphics offScreenGraphicsCtx;
private Thread animationThread;
private MediaTracker mediaTracker;
private SpriteManager spriteManager;
//Animation display rate, 12fps
private int animationDelay = 83;
private Random rand = new Random(System.currentTimeMillis());
private int message = 0 ; // 0 = no message (normal playing phase)
// 1 = press space to start
// 2 = press space for next level
// 3 = game PAUSED, press space to unpause
// 4 = You LOSE
public static void main(String[] args)
try
new Balls() ;
catch (java.net.MalformedURLException e)
System.out.println(e);
}//end main
public void start()
//Create and start animation thread
animationThread = new Thread(this);
animationThread.start();
public void init()
try
new Balls() ;
catch (java.net.MalformedURLException e)
System.out.println(e);
public Balls() throws java.net.MalformedURLException
{//constructor
// Load and track the images
mediaTracker = new MediaTracker(this);
backGroundImage = getImage(getDocumentBase(), "background.gif");
mediaTracker.addImage(backGroundImage, 0);
PressStart = getImage(getDocumentBase(), "press_start.gif");
mediaTracker.addImage(PressStart, 0);
NextStage = getImage(getDocumentBase(), "stage_complete.gif");
mediaTracker.addImage(NextStage, 0);
GamePaused = getImage(getDocumentBase(), "game_paused.gif");
mediaTracker.addImage(GamePaused, 0);
YouLose = getImage(getDocumentBase(), "you_lose.gif");
mediaTracker.addImage(YouLose, 0);
//Get and track 6 images to use
// for sprites
gifImages[0] = getImage(getDocumentBase(), "blueball.gif");
mediaTracker.addImage(gifImages[0], 0);
gifImages[1] = getImage(getDocumentBase(), "redball.gif");
mediaTracker.addImage(gifImages[1], 0);
gifImages[2] = getImage(getDocumentBase(), "greenball.gif");
mediaTracker.addImage(gifImages[2], 0);
gifImages[3] = getImage(getDocumentBase(), "yellowball.gif");
mediaTracker.addImage(gifImages[3], 0);
gifImages[4] = getImage(getDocumentBase(), "purpleball.gif");
mediaTracker.addImage(gifImages[4], 0);
gifImages[5] = getImage(getDocumentBase(), "orangeball.gif");
mediaTracker.addImage(gifImages[5], 0);
//Block and wait for all images to
// be loaded
try {
mediaTracker.waitForID(0);
}catch (InterruptedException e) {
System.out.println(e);
}//end catch
//Base the Frame size on the size
// of the background image.
//These getter methods return -1 if
// the size is not yet known.
//Insets will be used later to
// limit the graphics area to the
// client area of the Frame.
int width = backGroundImage.getWidth(this);
int height = backGroundImage.getHeight(this);
//While not likely, it may be
// possible that the size isn't
// known yet. Do the following
// just in case.
//Wait until size is known
while(width == -1 || height == -1)
System.out.println("Waiting for image");
width = backGroundImage.getWidth(this);
height = backGroundImage.getHeight(this);
}//end while loop
//Display the frame
setSize(width,height);
setVisible(true);
//setTitle("Balls");
//Anonymous inner class window
// listener to terminate the
// program.
this.addWindowListener
(new WindowAdapter()
{public void windowClosing(WindowEvent e){System.exit(0);}});
// Add a key listener for keyboard management
this.addKeyListener(this);
}//end constructor
public void run()
Point center_place = new Point(
backGroundImage.getWidth(this)/2-PressStart.getWidth(this)/2,
backGroundImage.getHeight(this)/2-PressStart.getHeight(this)/2) ;
pressStartSprite = new Sprite(this, PressStart, center_place, new Point(0, 0),true);
center_place = new Point(
backGroundImage.getWidth(this)/2-NextStage.getWidth(this)/2,
backGroundImage.getHeight(this)/2-NextStage.getHeight(this)/2) ;
NextStageSprite = new Sprite(this, NextStage, center_place, new Point(0, 0),true);
center_place = new Point(
backGroundImage.getWidth(this)/2-GamePaused.getWidth(this)/2,
backGroundImage.getHeight(this)/2-GamePaused.getHeight(this)/2) ;
GamePausedSprite = new Sprite(this, GamePaused, center_place, new Point(0, 0),true);
center_place = new Point(
backGroundImage.getWidth(this)/2-YouLose.getWidth(this)/2,
backGroundImage.getHeight(this)/2-YouLose.getHeight(this)/2) ;
YouLoseSprite = new Sprite(this, YouLose, center_place, new Point(0, 0),true);
BackgroundImage bgimage = new BackgroundImage(this, backGroundImage) ;
for (;;) // infinite loop
long time = System.currentTimeMillis();
message = 1 ; // "press start to begin"
while (message != 0)
repaint() ;
try
time += animationDelay;
Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
catch (InterruptedException e)
System.out.println(e);
}//end catch
boolean you_lose = false ;
for (int max_speed = 7 ; !you_lose && max_speed < 15 ; max_speed++)
for (int difficulty = 2 ; !you_lose && difficulty < 14 ; difficulty++)
boolean unfinished_stage = true ;
spriteManager = new SpriteManager(bgimage);
spriteManager.setParameters(difficulty, max_speed) ;
//Create 15 sprites from 6 gif
// files.
for (int cnt = 0; cnt < 15; cnt++)
if (cnt == 0)
Point position = new Point(
backGroundImage.getWidth(this)/2-gifImages[0].getWidth(this)/2,
backGroundImage.getHeight(this)/2-gifImages[0].getHeight(this)/2) ;
spriteManager.addSprite(makeSprite(position, 0, false));
else
Point position = spriteManager.
getEmptyPosition(new Dimension(gifImages[0].getWidth(this),
gifImages[0].getHeight(this)));
if (cnt < difficulty)
spriteManager.addSprite(makeSprite(position, 1, true));
else
spriteManager.addSprite(makeSprite(position, 2, true));
}//end for loop
time = System.currentTimeMillis();
while (!spriteManager.getFinishedStage() && !spriteManager.getGameOver())
// Loop, sleep, and update sprite
// positions once each 83
// milliseconds
spriteManager.update();
repaint();
try
time += animationDelay;
Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
catch (InterruptedException e)
System.out.println(e);
}//end catch
}//end while loop
if (spriteManager.getGameOver())
message = 4 ;
while (message != 0)
spriteManager.update();
repaint();
try
time += animationDelay;
Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
catch (InterruptedException e)
System.out.println(e);
}//end catch
you_lose = true ;
if (spriteManager.getFinishedStage())
message = 2 ;
while (message != 0)
spriteManager.update();
repaint();
try
time += animationDelay;
Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
catch (InterruptedException e)
System.out.println(e);
}//end catch
} // end for difficulty loop
} // end for max_speed
} // end infinite loop
}//end run method
private Sprite makeSprite(Point position, int imageIndex, boolean wind)
return new Sprite(
this,
gifImages[imageIndex],
position,
new Point(rand.nextInt() % 5,
rand.nextInt() % 5),
wind);
}//end makeSprite()
//Overridden graphics update method
// on the Frame
public void update(Graphics g)
//Create the offscreen graphics
// context
if (offScreenGraphicsCtx == null)
offScreenImage = createImage(getSize().width,
getSize().height);
offScreenGraphicsCtx = offScreenImage.getGraphics();
}//end if
if (message == 0)
// Draw the sprites offscreen
spriteManager.drawScene(offScreenGraphicsCtx);
else if (message == 1)
pressStartSprite.drawSpriteImage(offScreenGraphicsCtx);
else if (message == 2)
NextStageSprite.drawSpriteImage(offScreenGraphicsCtx);
else if (message == 3)
GamePausedSprite.drawSpriteImage(offScreenGraphicsCtx);
else if (message == 4)
YouLoseSprite.drawSpriteImage(offScreenGraphicsCtx);
// Draw the scene onto the screen
if(offScreenImage != null)
g.drawImage(offScreenImage, 0, 0, this);
}//end if
}//end overridden update method
//Overridden paint method on the
// Frame
public void paint(Graphics g)
//Nothing required here. All
// drawing is done in the update
// method above.
}//end overridden paint method
// Methods to handle Keyboard event
public void keyPressed(KeyEvent evt)
int key = evt.getKeyCode(); // Keyboard code for the pressed key.
if (key == KeyEvent.VK_SPACE)
if (message != 0)
message = 0 ;
else
message = 3 ;
if (key == KeyEvent.VK_LEFT)
if (spriteManager != null)
spriteManager.goLeft() ;
else if (key == KeyEvent.VK_RIGHT)
if (spriteManager != null)
spriteManager.goRight() ;
else if (key == KeyEvent.VK_UP)
if (spriteManager != null)
spriteManager.goUp() ;
else if (key == KeyEvent.VK_DOWN)
if (spriteManager != null)
spriteManager.goDown() ;
if (spriteManager != null)
spriteManager.setMessage(message) ;
public void keyReleased(KeyEvent evt)
public void keyTyped(KeyEvent e)
char key = e.getKeyChar() ;
//~ if (key == 's')
//~ stop = true ;
//~ else if (key == 'c')
//~ stop = false ;
//~ spriteManager.setStop(stop) ;
}//end class Balls
//===================================//
class BackgroundImage
private Image image;
private Component component;
private Dimension size;
public BackgroundImage(
Component component,
Image image)
this.component = component;
size = component.getSize();
this.image = image;
}//end construtor
public Dimension getSize(){
return size;
}//end getSize()
public Image getImage(){
return image;
}//end getImage()
public void setImage(Image image){
this.image = image;
}//end setImage()
public void drawBackgroundImage(Graphics g)
g.drawImage(image, 0, 0, component);
}//end drawBackgroundImage()
}//end class BackgroundImage
//===========================
class SpriteManager extends Vector
private BackgroundImage backgroundImage;
private boolean finished_stage = false ;
private boolean game_over = false ;
private int difficulty ;
private int max_speed ;
public boolean getFinishedStage()
finished_stage = true ;
for (int cnt = difficulty ; cnt < size(); cnt++)
Sprite sprite = (Sprite)elementAt(cnt);
if (!sprite.getEaten())
finished_stage = false ;
return finished_stage ;
public boolean getGameOver() {return game_over ;}
public void setParameters(int diff, int speed)
difficulty = diff ;
max_speed = speed ;
finished_stage = false ;
game_over = false ;
Sprite sprite;
for (int cnt = 0;cnt < size(); cnt++)
sprite = (Sprite)elementAt(cnt);
sprite.setSpeed(max_speed) ;
public SpriteManager(BackgroundImage backgroundImage)
this.backgroundImage = backgroundImage ;
}//end constructor
public Point getEmptyPosition(Dimension spriteSize)
Rectangle trialSpaceOccupied = new Rectangle(0, 0,
spriteSize.width,
spriteSize.height);
Random rand = new Random(System.currentTimeMillis());
boolean empty = false;
int numTries = 0;
// Search for an empty position
while (!empty && numTries++ < 100)
// Get a trial position
trialSpaceOccupied.x =
Math.abs(rand.nextInt() %
backgroundImage.
getSize().width);
trialSpaceOccupied.y =
Math.abs(rand.nextInt() %
backgroundImage.
getSize().height);
// Iterate through existing
// sprites, checking if position
// is empty
boolean collision = false;
for(int cnt = 0;cnt < size(); cnt++)
Rectangle testSpaceOccupied = ((Sprite)elementAt(cnt)).getSpaceOccupied();
if (trialSpaceOccupied.intersects(testSpaceOccupied))
collision = true;
}//end if
}//end for loop
empty = !collision;
}//end while loop
return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y);
}//end getEmptyPosition()
public void update()
Sprite sprite;
// treat special case of sprite #0 (the player)
sprite = (Sprite)elementAt(0);
sprite.updatePosition() ;
int hitIndex = testForCollision(sprite);
if (hitIndex != -1)
if (hitIndex < difficulty)
{ // if player collides with an hunter (red ball), he loose
sprite.setEaten() ;
game_over = true ;
else
// if player collides with an hunted (green ball), he eats the green
((Sprite)elementAt(hitIndex)).setEaten() ;
//Iterate through sprite list
for (int cnt = 1;cnt < size(); cnt++)
sprite = (Sprite)elementAt(cnt);
//Update a sprite's position
sprite.updatePosition();
//Test for collision. Positive
// result indicates a collision
hitIndex = testForCollision(sprite);
if (hitIndex >= 0)
//a collision has occurred
bounceOffSprite(cnt,hitIndex);
}//end if
}//end for loop
}//end update
public void setMessage(int message)
Sprite sprite;
//Iterate through sprite list
for (int cnt = 0;cnt < size(); cnt++)
sprite = (Sprite)elementAt(cnt);
//Update a sprite's stop status
sprite.setMessage(message);
}//end for loop
}//end update
public void goLeft()
Sprite sprite = (Sprite)elementAt(0);
sprite.goLeft() ;
public void goRight()
Sprite sprite = (Sprite)elementAt(0);
sprite.goRight() ;
public void goUp()
Sprite sprite = (Sprite)elementAt(0);
sprite.goUp() ;
public void goDown()
Sprite sprite = (Sprite)elementAt(0);
sprite.goDown() ;
private int testForCollision(Sprite testSprite)
//Check for collision with other
// sprites
Sprite sprite;
for (int cnt = 0;cnt < size(); cnt++)
sprite = (Sprite)elementAt(cnt);
if (sprite == testSprite)
//don't check self
continue;
//Invoke testCollision method
// of Sprite class to perform
// the actual test.
if (testSprite.testCollision(sprite))
//Return index of colliding
// sprite
return cnt;
}//end for loop
return -1;//No collision detected
}//end testForCollision()
private void bounceOffSprite(int oneHitIndex, int otherHitIndex)
//Swap motion vectors for
// bounce algorithm
Sprite oneSprite = (Sprite)elementAt(oneHitIndex);
Sprite otherSprite = (Sprite)elementAt(otherHitIndex);
Point swap = oneSprite.getMotionVector();
oneSprite.setMotionVector(otherSprite.getMotionVector());
otherSprite.setMotionVector(swap);
}//end bounceOffSprite()
public void drawScene(Graphics g)
//Draw the background and erase
// sprites from graphics area
//Disable the following statement
// for an interesting effect.
backgroundImage.drawBackgroundImage(g);
//Iterate through sprites, drawing
// each sprite
for (int cnt = 0;cnt < size(); cnt++)
((Sprite)elementAt(cnt)).drawSpriteImage(g);
}//end drawScene()
public void addSprite(Sprite sprite)
addElement(sprite);
}//end addSprite()
}//end class SpriteManager
//===================================//
class Sprite
private Component component;
private Image image;
private Rectangle spaceOccupied;
private Point motionVector;
private Rectangle bounds;
private Random rand;
private int message = 0 ; // number of message currently displayed (0 means "no message" = normal game)
private int max_speed = 7 ;
private boolean eaten = false ; // when a green sprite is eaten, it is no longer displayed on screen
private boolean wind = true ;
private boolean go_left = false ;
private boolean go_right = false ;
private boolean go_up = false ;
private boolean go_down = false ;
public Sprite(Component component,
Image image,
Point position,
Point motionVector,
boolean Wind
//Seed a random number generator
// for this sprite with the sprite
// position.
rand = new Random(position.x);
this.component = component;
this.image = image;
setSpaceOccupied(new Rectangle(
position.x,
position.y,
image.getWidth(component),
image.getHeight(component)));
this.motionVector = motionVector;
this.wind = Wind ;
//Compute edges of usable graphics
// area in the Frame.
int topBanner = ((Container)component).getInsets().top;
int bottomBorder = ((Container)component).getInsets().bottom;
int leftBorder = ((Container)component).getInsets().left;
int rightBorder = ((Container)component).getInsets().right;
bounds = new Rectangle( 0 + leftBorder, 0 + topBanner
, component.getSize().width - (leftBorder + rightBorder)
, component.getSize().height - (topBanner + bottomBorder));
}//end constructor
public void setMessage(int message_number)
message = message_number ;
public void setSpeed(int speed)
max_speed = speed ;
public void goLeft()
go_left = true ;
public void goRight()
go_right = true ;
public void goUp()
go_up = true ;
public void goDown()
go_down = true ;
public void setEaten()
eaten = true ;
setSpaceOccupied(new Rectangle(4000,4000,0,0)) ;
public boolean getEaten()
return eaten ;
public Rectangle getSpaceOccupied()
return spaceOccupied;
}//end getSpaceOccupied()
void setSpaceOccupied(Rectangle spaceOccupied)
this.spaceOccupied = spaceOccupied;
}//setSpaceOccupied()
public void setSpaceOccupied(
Point position){
spaceOccupied.setLocation(
position.x, position.y);
}//setSpaceOccupied()
public Point getMotionVector(){
return motionVector;
}//end getMotionVector()
public void setMotionVector(
Point motionVector){
this.motionVector = motionVector;
}//end setMotionVector()
public void setBounds(Rectangle bounds)
this.bounds = bounds;
}//end setBounds()
public void updatePosition()
Point position = new Point(spaceOccupied.x, spaceOccupied.y);
if (message != 0)
return ;
//Insert random behavior. During
// each update, a sprite has about
// one chance in 10 of making a
// random change to its
// motionVector. When a change
// occurs, the motionVector
// coordinate values are forced to
// fall between -7 and 7. This
// puts a cap on the maximum speed
// for a sprite.
if (!wind)
if (go_left)
motionVector.x -= 2 ;
if (motionVector.x < -15)
motionVector.x = -14 ;
go_left = false ;
if (go_right)
motionVector.x += 2 ;
if (motionVector.x > 15)
motionVector.x = 14 ;
go_right = false ;
if (go_up)
motionVector.y -= 2 ;
if (motionVector.y < -15)
motionVector.y = -14 ;
go_up = false ;
if (go_down)
motionVector.y += 2 ;
if (motionVector.y > 15)
motionVector.y = 14 ;
go_down = false ;
else if(rand.nextInt() % 7 == 0)
Point randomOffset =
new Point(rand.nextInt() % 3,
rand.nextInt() % 3);
motionVector.x += randomOffset.x;
if(motionVector.x >= max_speed)
motionVector.x -= max_speed;
if(motionVector.x <= -max_speed)
motionVector.x += max_speed ;
motionVector.y += randomOffset.y;
if(motionVector.y >= max_speed)
motionVector.y -= max_speed;
if(motionVector.y <= -max_speed)
motionVector.y += max_speed;
}//end if
//Move the sprite on the screen
position.translate(motionVector.x, motionVector.y);
//Bounce off the walls
boolean bounceRequired = false;
Point tempMotionVector = new Point(
motionVector.x,
motionVector.y);
//Handle walls in x-dimension
if (position.x < bounds.x)
bounceRequired = true;
position.x = bounds.x;
//reverse direction in x
tempMotionVector.x = -tempMotionVector.x;
else if ((position.x + spaceOccupied.width) > (bounds.x + bounds.width))
bounceRequired = true;
position.x = bounds.x +
bounds.width -
spaceOccupied.width;
//reverse direction in x
tempMotionVector.x =
-tempMotionVector.x;
}//end else if
//Handle walls in y-dimension
if (position.y < bounds.y)
bounceRequired = true;
position.y = bounds.y;
tempMotionVector.y = -tempMotionVector.y;
else if ((position.y + spaceOccupied.height)
> (bounds.y + bounds.height))
bounceRequired = true;
position.y = bounds.y +
bounds.height -
spaceOccupied.height;
tempMotionVector.y =
-tempMotionVector.y;
}//end else if
if(bounceRequired)
//save new motionVector
setMotionVector(
tempMotionVector);
//update spaceOccupied
setSpaceOccupied(position);
}//end updatePosition()
public void drawSpriteImage(Graphics g)
if (!eaten)
g.drawImage(image,
spaceOccupied.x,
spaceOccupied.y,
component);
}//end drawSpriteImage()
public boolean testCollision(Sprite testSprite)
//Check for collision with
// another sprite
if (testSprite != this)
return spaceOccupied.intersects(
testSprite.getSpaceOccupied());
}//end if
return false;
}//end testCollision
}//end Sprite class
//===================================//
Thanks for your help...Sorry,
Can you tell me how do you solve it because I have got the same problem.
Can you indicate me the topic where did you find solution.
Thank in advance. -
Questions about Java Servlets and JSP
Hi,
I'm a confident Java Programmer (and really enjoy using this language) but am very new to Java servlets and Java Server Pages.
I have previously worked with Perl on my web projects (simple 'league' style voting pages). I read in my 'Core Java' book that I should no longer use perl or even cgi.
I need to know more about Java servlets and Java Server Pages so I can make the switch to a 'real' programming language.
I have a few questions:
How should I start to learn JS and JSP?
How applicable will the java knowlegdge I have already be?
Are JSP common on the world wide web?
What tools do I need to start? (I currently develop in JBuilder and have Java 1.4.1 Standard Edition)
Is it likey my web host (and others) will support JSP?
Thank-you very much for helping a novice get started,
Regards,
PaulHi, Steve ...has to be frustrating! But do not despair.
Let's suppose the servlet it's named MyServlet on package org.servlets
WEB-INF should look:
WEB-INF
classes
org
servlets
MyServlet.class
web.xml
web.xml file should have this two declarations:
<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>org.servlets.MyServlet</servlet-class>
</servlet>
<!-- other servlets -->
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
<!-- other servlets mappings -->
</web-app>Now, once the container starts (Tomcat?), you should be able to see that servlet in:
http://localhost:8080/[my-context/]MyServletAnd what my-context is? The web application context. This string should be empty if your're deploying to the root context, otherwise should the context name. In Tomcat, deploying to root context defaults to using webapps/ROOT.
Sorry for my English, but I felt the need to answer your request. I hope it helps despite my writing. -
Question about Java MySQL connection
Hi guys, greetings to y'all, me name is Ryan, I'm new 'round here.
I have some questions, I have some application that I build with Java and using MSSQL Server 2000 as it's database, and now I want to try to use MySQL as it's database. I use MySQL server 5.0 and Navicat 8 for MySQL for the gateway and Win XP SP2 as my OS, what I want to know is, can you guys give me some connection string example for MySQL, for Java that is, I'm still learning in Java so sorry if I have some mistaken languages or code related words. Thanks a lot guys.
Best Regards.Hi zahid, thanks for the reply, so if I have this code, like this one
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con=DriverManager.getConnection("jdbc:odbc:FlightSource","","");
stat2=con.prepareStatement("insert into Passenger_Table(vPassenger_Name,vPassenger_gender,iPassenger_Age,vPassenger_Destination,vPass_FlightClass,vPass_FlightType,vDate_of_Issue,vDate_of_Departure,vDate_Expire,vForm_Payment,Card_No,vTotal_Price)values(?,?,?,?,?,?,?,?,?,?,?,?)");
stat2.setString(1,textNama.getText());
stat2.setString(2,(String.valueOf(entry2)));
stat2.setString(3,textUmur.getText());
stat2.setString(4,textTujuan.getText());
stat2.setString(5,(String)comboKelas.getSelectedItem());
stat2.setString(6,(String)comboJenisKeberangkatan.getSelectedItem());
stat2.setString(7,(String)comboTglTiket.getSelectedItem()+"/"+texttgltiket1.getText()+"/"+texttgltiket2.getText());
stat2.setString(8,(String)comboTglBerangkat.getSelectedItem()+"/"+texttglberangkat1.getText()+"/"+texttglberangkat2.getText());
stat2.setString(9,(String)comboTglKadaluwarsa.getSelectedItem()+"/"+texttglkadaluwarsa1.getText()+"/"+texttglkadaluwarsa2.getText());
stat2.setString(10,(String)comboPayType.getSelectedItem());
stat2.setString(11,textCardNo.getText());
//stat2.setFloat(12,Float.parseFloat(textHarga.getText()));
stat2.setString(12,textHarga.getText());
stat2.executeUpdate();
JOptionPane.showMessageDialog(null, "The Data has successfully Booked " );
catch(Exception exception)
JOptionPane.showMessageDialog(null,"Error encountered while entering data in the database: "+exception);
}I just simply change the Class.forName{} line right ?
What About the database name, considering in the code above I used ODBC (the ODBC name is FlightSource), so the database was configured when I create the ODBC, then how about MySQL, should I create ODBC too to configured the database that I wanna use ? -
Java 1.1.5 applets don't run in Netscape 6.1/6.2
I try to access a website with java-applets.
With Netscape 4.7x it's no problem. Java-Console says "Java 1.1.5". No java-plugin's installed.
With IE 5.x and 6 no problem.
Java Virtual Machine Build 3234 is installad
Systems NT4.0 and Win2000
With Netscape 6.1 and 6.2 those applets don't run (there is only a grey-area open where the applet should build up the content). I've seen there are couple of java-plugin's loaded in the Netscape 6 (NPOJI600.dll, NPJava130_01.dll, NPJava130_01a.dll, NPJava130_01b.dll and NPJava130_01c). As an idea I temporarly deleted them in the hope it would use JVM, as I suppose happens in Netscape 4.7x, were no java-plugin's are installed. But unfortunately it doesn't work either. It looks like Netscape 6.x can not refer to those java-components that the Netscape 4.7x uses.
Can I get somewhere the missing old plugin (1.1.5) or is there another way to make it work?
My search in java.sun.com told me that there seems to be no java 1.1.5 at all, so how can
Netscape talk about 1.1.5?
Thanks for any help....
Peter
PS) I have no experience in Java at all.Hello,
If you look at the release notes of Netscape they mention that Netscape 6.x will not run Java codes unless there 1.3.0_01 and above
Sometime you wonder where they get these ideas, that means that if you have an old applet it won't run with the new browser. I guess they never heard about backward compatibility
Yanick -
Hi all,
here is my problem, I am working on a demo for a customer, I am business consultant and I know nothing about java and I have noone next to give a hand, so please help.
I integrated a content in a Learning Management System. When launching this content in the LMS, an applet is created. I get a first page where I have to chose an option. When clicking on any of the options, I get nothing. On my java console, I can read this :
java.lang.NoSuchMethodError: javax.swing.UIManager.c()Ljava/lang/String;
at com.cbt.jasmine.Jasmine.Jasmine.b([DashoPro-V1.32-013000])
at com.cbt.jasmine.Jasmine.JasmineApplet.run([DashoPro-V1.32-013000])
at java.lang.Thread.run(Unknown Source)
What can I do to make this ******* content work.
Many thanks for your answers.
XToff.First of all, nothing is urgent to us, only to you.
Second, the error is clearly stated being NoSuchMethodError i.e. the program is trying to call a method that hasn't been for some reason included in the program.
Third, I have no idea what Learning Management System is (and I'm not the only one).
Fourth, why did you put "Re: URGENT !!!! I know nothing about java .... ;o)" as the topic instead of "Learning Management System"?
Maybe you are looking for
-
How to read product characteristics of a line item in Billing document?
Hi Friends, I need to read the product characteristics of a line item in Billing document. Can you please help me with which tables or function modules I should use? Thanks in advance. Regards Jaker.
-
I have downloaded firefox but when I open it I get the following message 'Firefox has detected that the server is redirecting the request for this address in a way that will never complete'. What do I do?
-
Loop or recursion in VC?
Hi all, is it possible to simulate a "while" loop or a recursion in VC. Obviously VC has no official tools or components for it. So I guess I will need a workaround. But I don't know how. What e.g. I want to achieve is an independent floating progres
-
How can i recover my bookmarks?
Hi, I've got a major problem on my hands now. All my firefox bookmarks are gone!! I had many valuable bookmarks there. I can't find them anywhere now. I went to the Firefox App Data folder and looked for any backups, but there were none. Is it possib
-
Gnome 3::Touchpad problem
Hi, I have a problem with gnome3. I have a new laptop Lenovo Thinkpad L420 (Intel Core i5-2410M + Intel HD 3000) with OS Archlinux 64-bit + Gnome3. When I disable touchpad, touchpad is off and I enable touchpad, touchpad is still disable::touchpad to