ProgrammingFreak wrote:
wmays wrote:
Just wondering, but is it possible to define methods like for? Sort of like this...
Code:
repeat(10) { //code to be executed }Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).
I'm thinking this kind of code? (I'm still learning )
Code:
static void repeat(int num) { for (int i = 0; i < num; i++) { } }
Um... that wouldn't actually do anything, other than go through a loop that does nothing num times.
ProgrammingFreak wrote:
Harakou wrote:
@ProgrammingFreak: What's Snap? I can't say I've heard of it.
Really? I think you would enjoy it.
It's an online version of Scratch that Jens and bharvey are developing.
Check it out here. Hope you enjoy. I've only played with it a little.
Oh, interesting! From what I see... it's basically online BYOB?
Offline
Harakou wrote:
ProgrammingFreak wrote:
wmays wrote:
Just wondering, but is it possible to define methods like for? Sort of like this...
Code:
repeat(10) { //code to be executed }Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).
I'm thinking this kind of code? (I'm still learning )
Code:
static void repeat(int num) { for (int i = 0; i < num; i++) { } }Um... that wouldn't actually do anything, other than go through a loop that does nothing num times.
Well, I know that.
I was just making that the example. I was wondering how you could have the code to repeat. Oh wait a minute.
Can you have a statement block as an argument like in Javascript?
Then you could do something like:
static void repeat(int num, /* place for block code argument */) { for (int i = 0; i < num; i++) { /* run block code /* } }
Harakou wrote:
ProgrammingFreak wrote:
Harakou wrote:
@ProgrammingFreak: What's Snap? I can't say I've heard of it.
Really? I think you would enjoy it.
It's an online version of Scratch that Jens and bharvey are developing.
Check it out here. Hope you enjoy. I've only played with it a little.Oh, interesting! From what I see... it's basically online BYOB?
Yes, that's what it is.
Offline
Working on making Pong I have movement down, I just need scorekeeping, ball mechanics, and a bit more left.
Offline
I might try learning this, cus I want to mod minecraft soooo bad
Offline
Everyone interested stay tuned for the first Undercover Study Hall Release of ALLCAPSRAGE studios! it will be available as a .zip file with all necessary libraries, images, class files and .java source files.
Offline
ugh. Exporting this seems like a pan, maybe it will be tomorrow XD I hae about 10 more minutes to find a solution. PROTIP: Only announce something if you're sure it's gonna work.
Offline
yep, it will probably be tomorrow first period. (any time between 8:00 CST and 9:25 CST) I COMPLETELY FORGOT about LWJGL's natives! Eclipse completely left them out!
Offline
does anyone know how to make something wait until a button is pressed?
ive tried making a loop raise a bogus variable (1) until a different variable (2) is a certain number
the button changes the other variable (2) by one but only if the variable (2) is 0
but it just gets unhappy and freezes and turns black
Last edited by GameHutSoftware (2012-02-28 10:38:48)
Offline
GameHutSoftware wrote:
does anyone know how to make something wait until a button is pressed?
ive tried making a loop raise a bogus variable (1) until a different variable (2) is a certain number
the button changes the other variable (2) by one but only if the variable (2) is 0
but it just gets unhappy and freezes and turns black
boolean mybuttonpressed = false
While(!mybuttonpressed){
}
public void keyPressed(KeyEvent ke)
{
if(ke.keyText(ke.keyCode) == "space")
mybuttonpressed = true;
}
sloppy and unterminatable but it works.
Offline
poopo wrote:
GameHutSoftware wrote:
does anyone know how to make something wait until a button is pressed?
ive tried making a loop raise a bogus variable (1) until a different variable (2) is a certain number
the button changes the other variable (2) by one but only if the variable (2) is 0
but it just gets unhappy and freezes and turns blackboolean mybuttonpressed = false
While(!mybuttonpressed){
}
public void keyPressed(KeyEvent ke)
{
if(ke.keyText(ke.keyCode) == "space")
mybuttonpressed = true;
}
sloppy and unterminatable but it works.
not a key
a jButton
Offline
GameHutSoftware wrote:
poopo wrote:
GameHutSoftware wrote:
does anyone know how to make something wait until a button is pressed?
ive tried making a loop raise a bogus variable (1) until a different variable (2) is a certain number
the button changes the other variable (2) by one but only if the variable (2) is 0
but it just gets unhappy and freezes and turns blackboolean mybuttonpressed = false
While(!mybuttonpressed){
}
public void keyPressed(KeyEvent ke)
{
if(ke.keyText(ke.keyCode) == "space")
mybuttonpressed = true;
}
sloppy and unterminatable but it works.not a key
a jButton
JButton button = new JButton("Click This Button"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ //Execute when button is pressed } });
That should work...
Last edited by ProgrammingFreak (2012-02-28 13:40:04)
Offline
ProgrammingFreak wrote:
wmays wrote:
Just wondering, but is it possible to define methods like for? Sort of like this...
Code:
repeat(10) { //code to be executed }Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).
I'm thinking this kind of code? (I'm still learning )
Code:
static void repeat(int num) { for (int i = 0; i < num; i++) { } }
it could be made simpler like this(using an anonymous inner class)
repeat(3, new code() {public void code() { }});
the repeat method:
public static void repeat(int num, code code){ for (int i = 0; i < num; i++) { code.code(); } }
code.java
public interface code { public void code(); }
Offline
TRocket wrote:
ProgrammingFreak wrote:
wmays wrote:
Just wondering, but is it possible to define methods like for? Sort of like this...
Code:
repeat(10) { //code to be executed }Is there a way to define the repeat(){} method? I'm making a library for scratch users who want to learn java... it will be like Scratch (sorta).
I'm thinking this kind of code? (I'm still learning )
Code:
static void repeat(int num) { for (int i = 0; i < num; i++) { } }it could be made simpler like this(using an anonymous inner class)
Code:
repeat(3, new code() {public void code() { }});the repeat method:
Code:
public static void repeat(int num, code code){ for (int i = 0; i < num; i++) { code.code(); } }code.java
Code:
public interface code { public void code(); }
Yeah, I said that later in the thread.
But this looks good.
Offline
poopo wrote:
I successfully made a draggable easily editable scratch type block in java.
Cool.
Offline
I am happy to announce releasing Pong as my first java game! You can read more on my Tumblr here. It's quite amazing that I've completed my first game exactly one month from my first compiled java project. If you look at the tumblr, I was able to compile on February 2nd and am releasing the finished product of all that work on February 29th!
Offline
Anyone know what I could use to make a GUI in java?
Offline
ihaveamac wrote:
Anyone know what I could use to make a GUI in java?
Use the javax.swing toolkit. Obviously that's a lot of classes, so here're some guides to hopefully help you along:
Oracle's Swing GUI guide
Thenewboston's tutorial You'll have to watch several videos - he uses quite a few to go over the basics. However, he's very good at explaining things in the simplest way possible if that's what you need.
Offline
It's here! ALLCAPSRAGE'S first Undercover Study Hall Update! This happens to be the first release of our Pong remake! You can download the .zip file here
In this release:
A functional Pong game
All required files to run Pong
pong.jar
lwjgl.jar and swing.jar (util libraries)
LWJGL required DLL's
Images (inside pong.jar)
Java source code (in the source folder)
Single player with AI opponent
Scorekeeping
To run Pong, unzip the folder and double-click pong.jar!
Offline