Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[JAVA] Need a good tutorial link...
#1
[] 
Now, i just hope the "No requests!" rule refers solely to LF2-sections&stuff :P

Hey ho ^^

As some (actually: none) people may know, i'm studying Computer Science right now.
Because the actual programming stuff is on a quite easy and basic level atm, though, i already started programming an own game in Java (yes, Java sucks, we all know. But it's the offical language for our course right now).
The game is supposed to be an basic tabletop strategy game, turn-based. However, up to now it only consists of MASSES of codes, methods and a big data file (value&stats&stuff).

The big problem (aka my request) is, i failed to find a useful, understandable and explaining tutorial for creating a GUI so far...
I just need a few basic menus and a clickable interface (which sends the data of where the click went to a method) in-game.

Anybody knows a good tutorial (site) or may even possesses a similar game as OpenSource file (usually studying other projects is always the best way to learn programming *obvious hint for people trying to learn DC*)?
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#2
java has a few libraries for guis. the tutorials on the sun/oracle website are quite good and explain the basics:
http://download.oracle.com/javase/tutorial/uiswing/ you can also follow the 2D Graphics one

if there are any apis ure unsure of then you can just look it up on the main javadoc thing (which is very good)

http://zetcode.com/tutorials/javagamestutorial/ and some examples of specific game implemenations using the default java libs - those examples r "c written in java" type of thing... dont pick up programming style from that - stuff should be in seperate objects and not just one big long program (thats what they should be teaching u if they decided on java)

swing gives you kinda sh**** preformance - but since its a turn based game and written in java (so preformance will never be ideal) i wouldnt worry abt it
...
Reply
Thanks given by: Alblaka
#3
Just quickread the second link.
Great tut for implementing sprites (and some other things i probably won't need right now.)

The first link seems to contain some more detailes instructions on how to load datafiles into the applet. I actually solved that problem with just typing all 1000+ (no joke, took me 1 1/2 hours) into Eclipse... but to know the faster solution could be useful XD


Just the Mouse-Clicking-Story left ^^'
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#4
need to do more reading and less typing ;)

look at the minesweeper example in that link, it deals with mouse stuff
more info abt those 2 can be found @ http://download.oracle.com/javase/1.4.2/...apter.html & http://download.oracle.com/javase/1.4.2/...Event.html

gd luck with ur game
...
Reply
Thanks given by:
#5
Jup, i found some good and easy to implement codes for mouse-interaction, should work ^^

However, i'm completely stuck on the image part...
It does display an image in a window now...
And that's all it does.

I can't get it to create multiple pictures in the same window :(
    JAVA-Code:
import javax.swing.JFrame;
 
public class GUI extends JFrame{
// <a href="http://zetcode.com/tutorials/javagamestutorial/basics/" target="_blank" rel="noopener" class="mycode_url">http://zetcode.com/tutorials/javagamestutorial/basics/</a>
//	<a href="http://download.oracle.com/javase/tutorial/uiswing/" target="_blank" rel="noopener" class="mycode_url">http://download.oracle.com/javase/tutorial/uiswing/</a>
 
	public GUI() {
        setTitle("WAR");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(800, 600);
        setLocationRelativeTo(null);
        setVisible(true);
        setResizable(false);
    }
    public static void main(String[] args) {
        GUI gui = new GUI();
        //MouseTracker application = new MouseTracker();
        gui.add(new ShowIcon(0,10,10));  <<<<<< HERE it should display the both images
        gui.add(new ShowIcon(0,120,120));  <<<<<< HERE it should display the both images
    }
 
}
 
// next class
 
import java.awt.Graphics;
import java.awt.Graphics2D;
 
import java.awt.Image;
 
import javax.swing.ImageIcon;
import javax.swing.JPanel;
 
 
public class ShowIcon extends JPanel {
 
	private Image uniticon;
	private int x;
	private int y;
 
    public ShowIcon(int nr, int x, int y)
    {
     	ImageIcon ii = new ImageIcon(this.getClass().getResource("sprites/unit000.png"));
     	uniticon = ii.getImage();
     	this.x=x;
     	this.y=y;
    }
 
 
       public void paint(Graphics g)
       {
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawImage(uniticon, this.x, this.y, null); 
        			  //FILE , X-Cord, Y-Cord, null
    }     
}


It will only display the image noted last. And sometimes, it won't display anything at all.

Silverthorn edited this post 12-10-2010 05:12 PM because:
pro-tip: [code=java] ;)
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#6
here is how i did it :

http://pastie.org/1365778
http://pastie.org/1365780

shows how to draw images, how to crop them + implements all the mouse stuff

then again its pretty bad... u shoud rly consider actually reading stuff on the official java websites i linked to (not the zed stuff). they show u properly structed stuff and not just hacked together stuff by somoene like me who hates OO programming and thinks it sucks :)
...
Reply
Thanks given by: Alblaka
#7
Hmmm... prob is, i need the game to load the icons/graphics MULTIPLE times... with that code i need to create a new Board object after every unit-movement, wouldn't i?

edit: So, further studied the code ( with these pasties you gave me):
If the GUI is created, it can add ONE "Board" to the screen. This Board can draw multiple images.
Which means, i need to create a GUI whenever i want the screen to refresh... which means, there will be another window created every time i want the picture to refresh... or somethign :(

Uhm... is there an option to delete/close GUI-created frames... It gets... funny, after the 100th GUI-Screen created. Actually i'm suprised it didn't crash XD
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#8
did you read any of the tutorials :p? u setup a timer which keeps calling paint, so paint gets called every 10ms or something and updates the screen ( http://zetcode.com/tutorials/javagamestu...ngsprites/ )

or you since this is turn based and the frame isn't likely to change that freq u can just paint it when ever a change is found ( http://zetcode.com/tutorials/javagamestu...nesweeper/ )

u should tihnk about the structure of the program - how the data will be represented etc

the way i would do it is create a class for the units then have an Array (or maybe ArrayList/LinkedList/HashMap/*insert collection here*) of all the units.

all paint will do is itterate over that collection and just draw them.

then the mouse handlers will be used to "move" the units - a.k.a change their x/y cord. this is probably where the majority of the logic will be located/called from
...
Reply
Thanks given by:
#9
(12-10-2010, 07:04 PM)Xidd Wrote:  did you read any of the tutorials :p? u setup a timer which keeps calling paint, so paint gets called every 10ms or something and updates the screen ( http://zetcode.com/tutorials/javagamestu...ngsprites/ )

or you since this is turn based and the frame isn't likely to change that freq u can just paint it when ever a change is found ( http://zetcode.com/tutorials/javagamestu...nesweeper/ )

Now, my question is HOW THE HELL do i paint it every time?

As far as my knoweledge goes the ONLY way to make the classes draw something is by creating a new GUI-object aka new window (which creates the image class drawing the things).


The logic for moving/attack/load/unload/reload/Arty/AA is completely done, i already have list for the units as well. I could implement the drawing sequence for these units as well, but it would kill my tests because i only have a single sprite atm (though, i could probably just create multiple units of the same type using the same sprite XD).


edit: another test...
Am i supposed to use GUI.image-thingy.repaint()?

editedit: Another look at the tutorial link
I'll make the vague guess that my above theory may be correct.. the example is using repaint as well...
If this seriously is the solution to the problem i'm working on for days now... i will... dunno... rage, probably. Or cheer... or cheer raging... or something similar like rage cheering.
My Creations: (Click to View)

Return (String) System.getNewsOfTheDay();
Barely active, expect slow responses. If at all.


Greetz,
Alblaka
Reply
Thanks given by:
#10
yes... you need to call repaint(); :p. the first example calls it through a timer that it setup
the minesweeper one calls it every time a peice is moved
...
Reply
Thanks given by: Alblaka




Users browsing this thread: 1 Guest(s)