I hope anti-spamming will work really effectively. I'm nearly got killed by the amount of spam PMs I had.
mangopearapples 16 Posting Whiz in Training
mangopearapples 16 Posting Whiz in Training
I hope anti-spamming will work really effectively. I'm nearly got killed by the amount of spam PMs I had.
Simple Geometry worked for me :) Thanks!
How can I detect a collision between 2 images? E.G if(Image1 collidesWith Image2){}
Thank you so much! Everything works now. Your English is fine.
Thanks again!
I'm trying to make it so when I press ESC, it RestoreScreen() but it doesn't work. Now I don't know whether it's my method RestoreScreen() or my listeners.
This is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class main extends JFrame implements MouseListener,KeyListener{
public void keyPressed(KeyEvent e) {
int rsKey = e.getKeyCode();
if(rsKey == KeyEvent.VK_ESCAPE || rsKey == 27){
s.RestoreScreen();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
main m = new main();
m.run(dm);
}
private title s;
private JTextField command;
private Image bg;
private Image ball;
private static int x = 0;
private static int y = 0;
private static boolean right = false;
private static boolean down = false;
private boolean loaded = false;
private boolean dojustonce = false;
Timer moveball = new Timer(50,new ActionListener(){
public void actionPerformed(ActionEvent e){
if(right == false){x-=6;}if(right == true){x+=6;}
if(down == false){y-=6;}if(down == true){y+=6;}
if(x <= 0){right = true;}if(x >= 750){right = false;}
if(y <= 0){down = true;}if(y >= 550){down = false;}
repaint();
}
});
public void DoJustOnce(){
repaint();
dojustonce = true;
}
public void paint(Graphics g){
if(!dojustonce){
g.clearRect(0,0,getWidth(),getHeight());
}
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
if(loaded){
g.drawImage(bg,0,0,null);
g.drawImage(ball,x,y,null);
}
g.drawString("Click To Start or Press Esc To Exit",180,500);
}
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.YELLOW);
setFont(new Font("Comic Sans MS",Font.PLAIN,24));
loaded = false;
loadpics();
command = new JTextField("Enter your command here. Press ESC to exit or press Enter to start."); …
Right; so if I'm right, s.RestoreScreen() returns a null?
And that means there's something wrong in my title class... But I swear it was working when I used thread.sleep(milliseconds). Do you guys want the code from title.java?
Pressing Esc doesn't do anything even though I have:
public void keyPressed(KeyEvent e) {
int rsKey = e.getKeyCode();
if(rsKey == KeyEvent.VK_ESCAPE){
s.RestoreScreen();
}
}
I've added the KeyListener.
Also I get lot's of errors or whatnot in the console box:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at main.keyPressed(main.java:9)
at java.awt.Component.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I have no idea what's wrong with my KeyPressed method...
I cut and pasted the KeyEvent code (int rsKey = e.getKeyCode();if(rskey ==) ect. to the KeyTyped method and this time, no errors in the console box yet it still doesn't 'RestoreScreen'.
Wow, I hadn't realized there was that much things about listeners...
Do you have to make class focusable? I don't think I've ever made a class focusable, not on purpose anyway and my ActionListener works always.
Anyway, thanks for everything again guys.
Hmm? Looks like i'll have to read a KeyListener tutorial...
I had already implemented the MouseListener so I don't think I can implement another thing.
The MouseListener is there for later.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class main extends JFrame implements MouseListener{
class keyl implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyReleased(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyTyped(KeyEvent e) {
s.RestoreScreen();
}
}
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
main m = new main();
m.run(dm);
}/*
while(right == false){x--;}while(right == true){x++;}
while(down == false){y--;}while(down == true){y++;}
if(x <= 0){right = true;}if(x >= m.getWidth()){right = false;}
if(y <= 0){down = true;}if(y >= m.getWidth());
*/
private title s;
private Image bg;
private Image ball;
private static int x = 0;
private static int y = 0;
private static boolean right = false;
private static boolean down = false;
private boolean loaded = false;
Timer moveball = new Timer(10,new ActionListener(){
public void actionPerformed(ActionEvent e){
if(right == false){x--;}if(right == true){x++;}
if(down == false){y--;}if(down == true){y++;}
if(x <= 0){right = true;}if(x >= 800){right = false;}
if(y <= 0){down = true;}if(y >= 600){down = false;}
repaint();
}
});
public void paint(Graphics g){
g.clearRect(0,0,getWidth(),getHeight());
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
if(loaded){
g.drawImage(bg,0,0,null);
g.drawImage(ball,x,y,null);
}
g.drawString("Click To Start or Press Any Key To Exit",180,500);
}
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.YELLOW);
setFont(new Font("Comic Sans MS",Font.PLAIN,24));
loaded = false;
loadpics();
addMouseListener(this);
addKeyListener(new keyl());
title s = new title();
moveball.start();
try{
s.setFullScreen(dm,this);
}
catch(Exception ex){}
}
public void loadpics(){
bg = new ImageIcon("C:\\Documents and Settings\\Lam\\My Documents\\My Pictures\\fun.png").getImage();
ball = new ImageIcon("C:\\Program Files\\Ds Game Maker\\Resources\\Sprites\\Ball.png").getImage();
loaded = …
I just realized that my KeyListener isn't working. Sorry for troubling you again but do you know why? I'm pretty sure RestoreScreen() works because I had already tested it with thread.sleep().
Oh yes, how silly of me :D . Sorry for that. Thanks again! It moves now but I think I should make the amount of milliseconds before the timer executes the 'actionPerformed' method a bit lower because it moves too slow!
Anyway, thanks again! I want to hug you guys!
Hmm, it's still not moving the ball image :S , the only code that I changed from before was changing the while to an if.
I see, so they cannot never end.
The while loop link you gave me says you can though, I think...
Anyway, problem solved. Thanks again!
Oh yeah! I know why now! See James, telling me made me understand :D
Though I might still be wrong.
Using If statements will work because it will execute the code every 1/2 a second because it's in a timer right?
I still don't understand why while loops work though.
Thanks James and Akill10!!
Huh? That code is a loop isn't it?
while(right){x++;}
while(!right){x--;}
while(down){y++;}
while(!down){y--;}
Okay, so I read through everything on the links. Thanks, I learned some more about numerical data but I think I already new what I read about while loops.
Anyway, this is what I think I want in just plain English.
While right is equal to true; increment variable x.
while right is equal to false; decrement variable x.
While down is equal to true; increment variable y.
While down is equal to false; decrement variable y.
Hmm, I have no idea. I understand that 'true' returns 1 and 'false' returns 0...
Maybe if you tell me why then I'll be able to do the rest :D .
Oh, well do you know why they're wrong?
Anyone?
OK, I used a timer and.... Nothing.
I don't know whether this is correct. I haven't changed the title class. Maybe if you can find the time?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class main extends JFrame implements MouseListener{
class keyl implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyReleased(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyTyped(KeyEvent e) {
s.RestoreScreen();
}
}
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
main m = new main();
m.run(dm);
}/*
while(right == false){x--;}while(right == true){x++;}
while(down == false){y--;}while(down == true){y++;}
if(x <= 0){right = true;}if(x >= m.getWidth()){right = false;}
if(y <= 0){down = true;}if(y >= m.getWidth());
*/
private title s;
private Image bg;
private Image ball;
private static int x = 0;
private static int y = 0;
private static boolean right = false;
private static boolean down = false;
private boolean loaded = false;
Timer moveball = new Timer(500,new ActionListener(){
public void actionPerformed(ActionEvent e){
while(right == false){x--;}while(right == true){x++;}
while(down == false){y--;}while(down == true){y++;}
if(x <= 0){right = true;}if(x >= 800){right = false;}
if(y <= 0){down = true;}if(y >= 600);
repaint();
}
});
public void paint(Graphics g){
g.clearRect(0,0,getWidth(),getHeight());
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
if(loaded){
g.drawImage(bg,0,0,null);
g.drawImage(ball,x,y,null);
}
g.drawString("Click To Start or Press Any Key To Exit",180,500);
}
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.YELLOW);
setFont(new Font("Comic Sans MS",Font.PLAIN,24));
loaded = false;
loadpics();
addMouseListener(this);
addKeyListener(new keyl());
title s = new title();
moveball.start();
try{
s.setFullScreen(dm,this);
}
catch(Exception ex){}
} …
Right, will making a different method instead of using the main method with the movement if the balls positions in a loop still burn CPU cycles as much or I should just use javax.swing.Timer?
So s.RestoreScreen() should work?
title.java code:
import javax.swing.*;
import java.awt.*;
public class title extends JFrame{
private GraphicsDevice vc;
public title(){
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
vc = env.getDefaultScreenDevice();
}
public void setFullScreen(DisplayMode dm,JFrame window){
window.setUndecorated(true);
window.setResizable(false);
vc.setFullScreenWindow(window);
if(dm != null && vc.isDisplayChangeSupported()){
try{
vc.setDisplayMode(dm);
}catch(Exception ex){}
}
}
public Window getFullScreenWindow(){
return vc.getFullScreenWindow();
}
public void RestoreScreen(){
Window w = vc.getFullScreenWindow();
if(w != null){
w.dispose();
}
vc.setFullScreenWindow(null);
}
}
Will nobody help?
Why won't this work? I'm trying to make a ball appear and move along my screen but it's failing :'( . I'm :( and also trying to make it so when you press any key it restores the full screen but that's also failing. :'( Can anyone help?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class main extends JFrame implements MouseListener{
class keyl implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyReleased(KeyEvent e) {
s.RestoreScreen();
}
@Override
public void keyTyped(KeyEvent e) {
s.RestoreScreen();
}
}
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
main m = new main();
m.run(dm);
while(right == false){x--;}while(right == true){x++;}
while(down == false){y--;}while(down == true){y++;}
if(x <= 0){right = true;}if(x >= m.getWidth()){right = false;}
if(y <= 0){down = true;}if(y >= m.getWidth());
}
private title s;
private Image bg;
private Image ball;
private static int x = 0;
private static int y = 0;
private static boolean right = false;
private static boolean down = false;
private boolean loaded = false;
public void paint(Graphics g){
g.clearRect(0,0,getWidth(),getHeight());
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
if(loaded){
g.drawImage(bg,0,0,null);
g.drawImage(ball,x,y,null);
}
g.drawString("Click To Start or Press Any Key To Exit",180,500);
}
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.YELLOW);
setFont(new Font("Comic Sans MS",Font.PLAIN,24));
loaded = false;
loadpics();
addMouseListener(this);
addKeyListener(new keyl());
title s = new title();
try{
s.setFullScreen(dm,this);
}
catch(Exception ex){}
}
public void loadpics(){
bg = new ImageIcon("C:\\Documents and Settings\\Lam\\My Documents\\My Pictures\\fun.png").getImage();
ball = new ImageIcon("C:\\Program Files\\Ds Game Maker\\Resources\\Sprites\\Ball.png").getImage();
loaded = true; …
Oh, that's a shame, just got my IPhone and no game developing :'( .
Buying a Mac for Christmas then :) . Thanks for the info guys.
I'm sure you can code IPhone games with java, it's cross-platformed with the IPhone I think apple announced. Maybe they didn't and it was a vision I saw in the wormhole on my bedroom window.
Anyway, so the only way is to code using Objective-C?
How can I develop IPhone games with Java?
I've tried something called XMLVL but that doesn't seem to be up to date and I can't use it because they don't have anything I can download to use...
So is there any other alternative?
I see, well thanks! Seems to be working. :)
Thank you! It removed the error! I don't know whether it actually removes the error or hides it though so I'll see.
OK.
It comes up with an error (red zig zag line underneath code)after I used Player player = new Player(); and this should work according to some examples.
The error is: "Access restriction: The type Player is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\ext
\jmf.jar"
I read somewhere, that you can make Eclipse ignore restrictions but I still fail at finding out how to do that :(
Also I am using JMF.
Yay! Found out how to install JMF now. Some of the examples don't work though, something about restrictions on Eclipse but I suppose that's for the Eclipse forum.
James, thanks but I tried using the JLayer example in your link but Eclipse still gave restriction errors so I guess this was my real problem.
Thank you guys!
Yays, INSERT clause? Time to get searching!!
Thanks for the help and links and references and stuff.
How can I send some data to a MySQL database?
I'm using php.
I did look it up with my best friend, google.
Didn't really find anything useful. Nothing about how to use it or anything.
Also I meant if he could explain how to use it.
Can you explain further please?
I simply do not believe you.
Oof, you really should believe me.
I searched How to use JMF instead of JMF Documentation.
Thanks for the references!!
looked everywhere!!! I found JMStudio that got installed with JMF but I don't know how to use it still...
Is there anyway to play an mp3 file in java?
P.S I'm new here, hello world?