hi , I am developing a game wherein i need to place a map( static ). The cities in this map need to be traversed .
I was wondering if anybody could help me with the following :
1. how do I place the map on the panel ? ( using what.... )
2. How do i traverse it step by step on the roll of a dice? ( the moves should be auto generated i.e. the user is not allowed to drag his marble on the board .)
12 2975 JosAH 11,448
Recognized Expert MVP
hi , I am developing a game wherein i need to place a map( static ). The cities in this map need to be traversed .
I was wondering if anybody could help me with the following :
1. how do I place the map on the panel ? ( using what.... )
2. How do i traverse it step by step on the roll of a dice? ( the moves should be auto generated i.e. the user is not allowed to drag his marble on the board .)
You could represent that map as a simple image which you can draw in your JPanel.
The marbles are best drawn on the 'glasspanel' of the JFrame itself; they appear
'on top' of the map then. Read all about it in the API documentation of the JFrame.
kind regards,
Jos
Thanks alot Josah...........
The first part of the task is achieved ! i.e. I've put the map on a JLabel n then put tht JLabel on the respective panel. I hope this is what u suggested ( if there is some kind of variation , plz let me know )
Now , the second part : Placing the marbles on the map
Like u suggested the use of glasspanes ,I have no clue abt. the same !
I was wondering if u use a JPanel and set it as opaque, will it achieve the same effect ?
kind regards,
Malavika
JosAH 11,448
Recognized Expert MVP
Now , the second part : Placing the marbles on the map
Like u suggested the use of glasspanes ,I have no clue abt. the same !
I was wondering if u use a JPanel and set it as opaque, will it achieve the same effect ?
kind regards,
Malavika
You're on the right track: a glass pane is a non-opaque pane in front of all the
other stuff in your JFrame. You should set your JPanel non-opaque and visible: -
JPanel myGlassPane= new JPanel(<suitable layout manager>);
-
myGlassPane.setOpaque(false);
-
myGlassPane.setVisible(true);
-
-
myFrame.setGlassPane(myGlassPane);
-
When you add a component, icon, or whatever to the myGlassPane component
it will show up in front of the image which is drawn in your normal content pane
somewhere.
As an alternative, if you want marbles to pass in front of each other, you could
have a look at the JLayeredPane class.
kind regards,
Jos
You're on the right track: a glass pane is a non-opaque pane in front of all the
other stuff in your JFrame. You should set your JPanel non-opaque and visible: -
JPanel myGlassPane= new JPanel(<suitable layout manager>);
-
myGlassPane.setOpaque(false);
-
myGlassPane.setVisible(true);
-
-
myFrame.setGlassPane(myGlassPane);
-
When you add a component, icon, or whatever to the myGlassPane component
it will show up in front of the image which is drawn in your normal content pane
somewhere.
As an alternative, if you want marbles to pass in front of each other, you could
have a look at the JLayeredPane class.
kind regards,
Jos
Jos,
when u say " myFrame.setGlassPane(myGlassPane);"
here myFrame is gonna be the panel wherein I have my map rite ???
n then like I added the map to the panel in the following way : -
-
JPanel pnlmap=new JPanel();
-
ImageIcon imgicon =new ImageIcon("mainMap.gif");
-
JLabel lblmapimg=new JLabel(imgicon);
-
pnlmap.add(lblmapimg);
-
getContentPane.add(pnlmap,BorderLayout.CENTER);
-
-
I can place the marbel image in a similar style of coding ( i.e. placing an imge on d label n then adding the label to the panel .....) as well rite ??
or is there any variation to it ????
regards,
Malavika
JosAH 11,448
Recognized Expert MVP
Jos,
when u say " myFrame.setGlassPane(myGlassPane);"
here myFrame is gonna be the panel wherein I have my map rite ???
Erm, no; if you want your map (image) stored stored in just a JPanel which is
part of the JFrame, use the alternative method I suggested. Read up on the
JLayeredPane class; it can do the job too.
Stick your image map in the lowest layer and put your marble in a layer on top
of it.
kind regards,
Jos
Erm, no; if you want your map (image) stored stored in just a JPanel which is
part of the JFrame, use the alternative method I suggested. Read up on the
JLayeredPane class; it can do the job too.
Stick your image map in the lowest layer and put your marble in a layer on top
of it.
kind regards,
Jos
Hey, I used JLayeredPane n got it working !
Thanks Alot!
I am now able to place a marble on top of the map !
the next thing tht I need to know is.......
On the roll of the dice the marble takes the respective no. of steps.
These no. of steps will b taken automatically i.e. the player will not be allowed to drag the marble n place it ( so to avoid validation i.e. if the player has dragged only the rite no. of steps ).
The system will do they placing of marbles at appropriate pos.
There in all 34 positions !
I was thinking of storing the co-ordinates of these 34 positions ( in what ?????)
n once the dice is rolled goto d appropriate pos using the array of co-ordinates !
After reaching the 34 th pos d player should be able to go back to pos 1 n continue the cycle !
so what i want to exactly know is :
1. Is my track of thinking rite ?
2. What sort of a collection is likely to be the best for storing the co-ordinates ?
3. how do i loop back ?( i.e. after pos 34 goto 1 pos....)
Kind regards,
Malavika
JosAH 11,448
Recognized Expert MVP
so what i want to exactly know is :
1. Is my track of thinking rite ?
2. What sort of a collection is likely to be the best for storing the co-ordinates ?
3. how do i loop back ?( i.e. after pos 34 goto 1 pos....)
Kind regards,
Malavika
1) I don't know; you were talking about all sorts of ideas.
2) I think an array or an ArrayList could do the job easily; design a 'Coordinate'
class (it should be a simple x,y object) and have an array(list) of those.
3) -
int curPos= ...
-
int nxtPos= (++curPos)%34;
-
... assuming that position indexes start at 0, not 1; Java likes it that way.
kind regards,
Jos
1) I don't know; you were talking about all sorts of ideas.
2) I think an array or an ArrayList could do the job easily; design a 'Coordinate'
class (it should be a simple x,y object) and have an array(list) of those.
3) -
int curPos= ...
-
int nxtPos= (++curPos)%34;
-
... assuming that position indexes start at 0, not 1; Java likes it that way.
kind regards,
Jos
1. Am i thinking in the rite direction with ref to : Having a list of co-ordinates n then traversing these co-ordinates using the list !
is there a better way to achieve to the same kind of functionality ?
kind regards,
Malavika
JosAH 11,448
Recognized Expert MVP
1. Am i thinking in the rite direction with ref to : Having a list of co-ordinates n then traversing these co-ordinates using the list !
is there a better way to achieve to the same kind of functionality ?
kind regards,
Malavika
I don't know; your idea makes sense especially because you want your coordinates
to be indexed, i.e. coordinate #0, coordinate #1 etc.
kind regards,
Jos
I don't know; your idea makes sense especially because you want your coordinates
to be indexed, i.e. coordinate #0, coordinate #1 etc.
kind regards,
Jos
There is a totally different thing tht i wish to ask you :
how can i read data from a file n put it on a screen a JFrame ........
i was trying to do the following but it doesnt seem to work -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
-
public class Instructions extends JFrame
-
{
-
FileInputStream in;
-
JPanel pnlinstructions;
-
JTextArea txtarea;
-
Container content;
-
byte data[];
-
-
-
public Instructions()
-
{
-
-
pnlinstructions=new JPanel();
-
txtarea=new JTextArea();
-
try
-
{
-
in = new FileInputStream("abc.txt");
-
data = new byte[10000];
-
-
BufferedInputStream bis = new BufferedInputStream(in);
-
DataInputStream dis = new DataInputStream(bis);
-
-
int filelength = dis.read(infile);
-
String filestring = new String(infile, 0, filelength);
-
System.out.println("FILE CONTENT=" + filestring);
-
txtarea.setText(filestring);
-
-
}
-
catch(IOException e)
-
{}
-
-
-
-
setTitle("Instructions");
-
pnlinstructions.add(txtarea);
-
-
content = getContentPane();
-
content.add(pnlinstructions);
-
-
-
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
-
setSize(500,500);
-
setVisible(true);
-
-
}
-
public static void main(String args[])
-
{
-
new Instructions();
-
}
-
}
-
plz suggest something !!
kind regards ,
Malavika
There is a totally different thing tht i wish to ask you :
how can i read data from a file n put it on a screen a JFrame ........
i was trying to do the following but it doesnt seem to work -
import java.util.*;
-
import java.io.*;
-
import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
-
-
public class Instructions extends JFrame
-
{
-
FileInputStream in;
-
JPanel pnlinstructions;
-
JTextArea txtarea;
-
Container content;
-
byte data[];
-
-
-
public Instructions()
-
{
-
-
pnlinstructions=new JPanel();
-
txtarea=new JTextArea();
-
try
-
{
-
in = new FileInputStream("abc.txt");
-
data = new byte[10000];
-
-
BufferedInputStream bis = new BufferedInputStream(in);
-
DataInputStream dis = new DataInputStream(bis);
-
-
int filelength = dis.read(infile);
-
String filestring = new String(infile, 0, filelength);
-
System.out.println("FILE CONTENT=" + filestring);
-
txtarea.setText(filestring);
-
-
}
-
catch(IOException e)
-
{}
-
-
-
-
setTitle("Instructions");
-
pnlinstructions.add(txtarea);
-
-
content = getContentPane();
-
content.add(pnlinstructions);
-
-
-
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
-
setSize(500,500);
-
setVisible(true);
-
-
}
-
public static void main(String args[])
-
{
-
new Instructions();
-
}
-
}
-
plz suggest something !!
kind regards ,
Malavika
Do not use DataInputStream for reading textfiles.
See Sun's tutorial on JTextComponents and use one of those components to display your file contents.
JosAH 11,448
Recognized Expert MVP
plz suggest something !!
Read the API documentation of the JTextArea class: it can read from a Reader
and setup itself with the content of the Reader.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mickel Grönroos |
last post by:
Hi,
I'm trying to put an Tkinter.Entry of fixed size onto a specific location
on a canvas using the place manager. The idea is that one can double-click
a rectangle object on a canvas to get an...
|
by: Mickel Grönroos |
last post by:
Hi,
I have a Tkinter.Canvas of variable width. Is there a standard way of
asking the canvas which parts of it that is visible? I.e. on the
horizontal scale, I would like to know at what fraction...
|
by: Andrew Poulos |
last post by:
Is there a right/best way to draw an ellipse using Canvas? (With VML
there's the v:oval element which makes the exercise trivial). I tried
drawing a 360 degree arc (a circle) and then scaling it...
|
by: Aaron Gray |
last post by:
Hi,
I have put together a bit of JavaScript to make a square resizable canvas :-
http://www.aarongray.org/Test/JavaScript/resizable.html
Problems I have :-
a) I cannot seem to center it...
|
by: moondaddy |
last post by:
I'm working in a WPF windows application and am wondering if it's possible
to rotate a Canvas or user control derived from Canvas. I created a user
control which derives from Canvas and I need to...
| |
by: TMS |
last post by:
Schools over!!! Now its time to play.
I would like to learn how to make objects move from one location to the next on a canvas widget. For example:
from Tkinter import *
class square:...
|
by: Nebulism |
last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from...
|
by: devnew |
last post by:
hi
i am new to tkinter and would like some help with canvas
i am doing validation of contents of a folder and need to show the
ok/error messages on a canvas
resultdisplay =Canvas(...)...
|
by: blaine |
last post by:
Hey everyone!
I'm not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).
Anyway, all is...
|
by: moondaddy |
last post by:
I have a wpf project where I use a canvas to drag shapes around. when I
drag a shape beyond the right or bottom side I get scrollbars which is good.
I also get scrollbars when I zoom in and a...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |