well, I am working on a multiplayer game, how would I make a typical game select interface, like AOE or AOM, BF2142. those kinda things.
if this is not possible what have some of you guys done to get around this?
thx in advance,
h3ckboy
well, I am working on a multiplayer game, how would I make a typical game select interface, like AOE or AOM, BF2142. those kinda things.
if this is not possible what have some of you guys done to get around this?
thx in advance,
h3ckboy
if your using gtge just create a new game instance for your intro screen then depending on what you select on that screen determines where you go in your game
if you look at the testnetworked game class youll notice that it extends game. if you look at the deepspacegameengine class youll see it extends game engine…lol i will send you an example a blank skeleton for you to play with.
sry if I wasnt specific enough, I mean the gui involved in selecting the game.
ahh sorry you want buttons and stuff try the gtge gui jar
yeah, I dont know how to do it with that even 
thx for the reply
So easy. You either use some sort of GUI layouts (like Swing or FengGUI) or you can just make one from scratch, which does the trick just fine usually.
Easy as cheesy. Text and sliders and things get a bit more complicated, but they’re still pretty easy.
so you are saying that, I should have a series of pictures that are ina n array, and then if there is a click, then it cycles throught the array, and checks if the click is within those bounds??
This is a very simple button example. You would store these in an array or other collection and iterate over it when the mouse is released, draw, etc. You will need to implement an action listener to handle the button being pressed. http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Vector;
public class SimpleButton implements MouseListener {
BufferedImage img;
ActionEvent action;
boolean active;
Rectangle2D bounds;
boolean focus;
Vector<ActionListener> listeners;
public SimpleButton(BufferedImage img, String cmd, float x, float y) {
this(img, cmd, x, y, null);
}
public SimpleButton(BufferedImage img, String cmd, float x, float y, ActionListener listener) {
this.img = img;
action = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, cmd);
active = true;
bounds = new Rectangle2D.Float(x, y, img.getWidth(), img.getHeight());
listeners = new Vector<ActionListener>();
if(listener!=null)
listeners.add(listener);
}
public boolean addActionListener(ActionListener listener){
return listeners.add(listener);
}
public boolean removeActionListener(ActionListener listener){
return listeners.remove(listener);
}
public void draw(Graphics2D g) {
if(!active)
return;
g.drawImage(img, (int)bounds.getX(), (int)bounds.getY(), null);
}
public Rectangle2D getBounds() {
return bounds;
}
public boolean contains(Point p){
return bounds.contains(p);
}
@Override
public void mouseClicked(MouseEvent e) {// TODO show clicked in graphic
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {ximport java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Vector;
public class SimpleButton implements MouseListener {
BufferedImage img;
ActionEvent action;
boolean active;
Rectangle2D bounds;
boolean focus;
Vector<ActionListener> listeners;
public SimpleButton(BufferedImage img, String cmd, float x, float y) {
this(img, cmd, x, y, null);
}
public SimpleButton(BufferedImage img, String cmd, float x, float y, ActionListener listener) {
this.img = img;
action = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, cmd);
active = true;
bounds = new Rectangle2D.Float(x, y, img.getWidth(), img.getHeight());
listeners = new Vector<ActionListener>();
if(listener!=null)
listeners.add(listener);
}
public boolean addActionListener(ActionListener listener){
return listeners.add(listener);
}
public boolean removeActionListener(ActionListener listener){
return listeners.remove(listener);
}
public void draw(Graphics2D g, int x, int y) {
if(!active)
return;
g.drawImage(img, x+(int)bounds.getX(), y+(int)bounds.getY(), null);
}
public Rectangle2D getBounds() {
return bounds;
}
public boolean contains(Point p){
return bounds.contains(p);
}
@Override
public void mouseClicked(MouseEvent e) {// TODO show clicked in graphic
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
for(ActionListener listener: listeners)
listener.actionPerformed(action);
}
}
}
}
I am looking into that, did you just write that code.
thx very much, you are a life saver 
I just stripped down one I already wrote, you probably need to clean it up some if you want to use it.
yeah you double pasted the code, but no worries 
umm, I am just curious, what is the string cmd supposed to be?
It is whats given to your action listener when you call ActionEvent.getActionCommand(). It’s just a way to tell which button is being pressed.
Or, a simpler way.
public void mouseClicked(MouseEvent e)
{
//Do a simple bounding box check to see if we clicked in button 1.
if (e.getX() >= button1.getX() + button1.getWidth() &&
e.getY() >= button1.getY() + button1.getHeight() &&
e.getX() <= button1.getX() &&
e.getY() <= button1.getY())
{
doStuffForButton1();
}
else if (e.getX() >= button2.getX() + button2.getWidth() &&
e.getY() >= button2.getY() + button2.getHeight() &&
e.getX() <= button2.getX() &&
e.getY() <= button2.getY())
{
doStuffForButton2();
}
else if (e.getX() >= button3.getX() + button3.getWidth() &&
e.getY() >= button3.getY() + button3.getHeight() &&
e.getX() <= button3.getX() &&
e.getY() <= button3.getY())
{
doStuffForButton3();
}
//etc.
}
If you don’t have very many UI elements, this works. My example doesn’t really help my case much because it’s very object oriented (which defeats the purpose of not just using a List). Typically I use screen coordinates, like,
public void mouseClicked(MouseEvent e)
{
//If the click is in the UI area, which is considered the top 5/6 of the screen...
if (e.getY() >= 5.0f * Screen.getHeight() / 6.0f)
{
//All my buttons are evenly sized, and there are three of them, and they take up the bottom of the screen.
if (e.getX() <= Screen.getWidth() / 3.0f)
{
doButton1();
}
else if (e.getX() <= 2.0f * Screen.getWidth() / 3.0f)
{
doButton2();
}
else
{
doButton3();
}
}
}
That way is quick n dirty, and not object oriented at all. However, if you’re like me and sometimes you don’t want to bother making a Button object and giving it coordinates and all that, and you just want to make a single PNG that takes up the bottom sixth of the screen, then this does the trick just fine. It all depends on what you’re looking for. With A Lasting Impression, all the UI on the bottom is done this way, but that was because it was for a timed competition and so I did it as fast as possible. Obviously doing it like this doesn’t help when you want to change it later.
well, the amount off items ont he list is dynamic so…
I am thinking along the lines of dividing the y by the total number of buttons. Then cut off the decimals, and then just get that value from a list of games. get the name of the game from the list. And then I have the game name.
is this a realistic idea?
capturing mouse input is already built into gtge no need to make your own listeners unless your using swing…
heres a full simple example…
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.golden.gamedev.*;
import com.golden.gamedev.object.*;
import com.golden.gamedev.engine.*;
public class mytestgame extends Game{
private static int mousexcord = 0;
private static int mouseycord = 0;
private static Image buttonimage;
private boolean buttonwasclicked =false;
PlayField playfield;
public void initResources(){
buttonimage = getImage("button.jpg");
playfield = new PlayField();
}
public void update(long elapsedTime){
mousexcord = getMouseX();
mouseycord = getMouseY();
if(mousexcord > 73 && mousexcord < 157){
if(mouseycord > 75 && mouseycord < 95){
if(bsInput.getMousePressed() != BaseInput.NO_BUTTON) {
if(bsInput.getMousePressed() == MouseEvent.BUTTON1) {
buttonwasclicked=true;
}
}
}
}
playfield.update(elapsedTime);
}
public void render(Graphics2D g){
playfield.render(g);
g.setColor(Color.white);
g.fillRect(0,0,800,600);
g.drawImage(buttonimage,73,75,null);
Font font1 = new Font("Verdana", Font.BOLD, 14);
g.setFont(font1);
g.setColor(Color.black);
if(buttonwasclicked ==true){
g.drawString( "Button Was Left Clicked" , 75, 120);
}
else{
g.drawString( "Waiting for button to be Clicked" , 75, 120);
}
}
public static void main(String[] args)throws java.io.IOException{
GameLoader game = new GameLoader();
game.setup(new mytestgame(), new Dimension(800,600), false);
game.start();
}
}
I am hoping to use swing, thank you all for your advice, I am going to try a simple idea for now, and then I will switch up to you guys’s later ;).
thx,
h3ckboy
HAHA, I found the best possible way ever!!!
a JList!! it does everything for me WOHOO.
here is a link if noone knows what I am talking about:
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html
thx for all of the help.
P.S: Mark I actually found this int he mmorpg example you gave me lol 
Yeah, JList is pretty good, but what I don’t like about Swing is that you can’t really customize its look very much - you’ll always have fairly ugly UI’s. I typically create PNGs and draw everything right into the game - lists are pretty easy to do.
public class UIList
{
private int scrollAmount;
private ArrayList<ListObject> items;
private int itemWidth, itemHeight;
private int width, height;
private int x, y;
public UIList(int drawX, int drawY, int wid, int hi, int iWidth, int iHeight, int initialSize, int initialScroll)
{
x = drawX;
y = drawY;
width = wid;
height = hi;
itemWidth = iWidth;
itemHeight = iHeight;
items = new ArrayList<ListObject>(initialSize);
scrollAmount = initialScroll;
}
public void draw(Graphics g)
{
//Draw the back of the UIList.
g.setColor(myBackColor);
g.fillRect(x,y,width,height);
//Figure out the visible items in the list.
int firstVisibleIndex = Math.abs(scrollAmount / itemHeight);
int lastVisibleIndex = Math.min(height / itemHeight + firstVisibleIndex, items.size());
//Draw all the visible items. Note that you will actually be drawing one less item than the size of the list.
for (int i = firstVisibleIndex; i < lastVisibleIndex; i++)
{
ListObject lo = items.get(i);
g.setColor(lo.getColor());
g.fillRect(x, y + i*itemHeight + scrollAmount, itemWidth, itemHeight);
g.setColor(lo.getBorderColor());
g.drawRect(x, y + i*itemHeight + scrollAmount, itemWidth, itemHeight);
g.drawImage(lo.getIcon(), x, y + i*itemHeight + scrollAmount, null);
}
//Draw the front of the UI list. We need the border at the top to overlap half-drawn items.
g.setColor(myBorderColor);
g.fillRect(x,y-itemHeight,width,itemHeight);
g.fillRect(x,y+width-itemHeight,width,itemHeight);
//Draw the scrollbar.
drawScrollbar();
}
//Assuming this was only called if the click happened within the list.
public void mouseClicked(int xPos, int yPos)
{
if (clickedOnUpScroll(xPos,yPos))
{
scrollAmount -= scrollSpeed;
}
else if (clickedOnDownScroll(xPos,yPos))
{
scrollAmount += scrollSpeed;
}
else
{
int clickedIndex = (yPos - y + scrollAmount) / itemHeight;
doSelectedItem(clickedIndex);
}
}
}
I just made that now, so some things might not work (specifically the right number of elements being drawn, there might need to be a -1 or a +1 somewhere) and I didn’t put all the functionality in. But, I just did that in 15 minutes… it’s really quite simple, and looks way better than JList.
kk, I willt ake a look into it
thx,
h3ckboy
EDIT:hmm, I discovered that it is not finished, but I guess you mentioned that. If I have some spare time I will finish this, because I agree that I could make the UI better. Cuase the button goes all the way across and it is all just jacked up.