I am currently working on a project in which I need to have a textGrid displaying a series of numbers.
I downloaded two textGrid classes that seem unable to allow me to enter text into them, or move around the grids using the keyboard.
I asked a friend of mine who mentioned I should attempt to write my own class, but I have no idea of how to do it properly so that values display correctly.
If anybody is able to either write me a demonstration class or explain how I could go about this endevour, it would be greatly appreciated.
Thanks
That's the problem. I don't have any documentation with them
I can get the textgrid to display in the applet, but it doesn't do what it should i.e it just shows a series of boxes according to my specifications.
I realise that I can possibly clarify what I want better:
I'm looking for some kind of code that will allow me to display a series to editable textareas in this fashion:
_____________
|6|5|3|4|4|0|4|
|7|4|8|9|9|5|6| etc.
I need to be able to move between the individual cells with the keyboard arrow keys and each cell can accomodate a maximum of 2 characters.
So it sounds that you are invoking the textGrid class and can change the rows and columns.
Did you get the code for these classes?
A shot in the dark - there is a method which probably takes row, column, and text or string as arguments. Something such as "writeGrid()" or "addToGrid()" - can you find a method such as this?
Thanks a lot sjalle, this class is just what I need.
I have one or two problems that I can't quite figure out though.
How do I specify the number of rows and columns, is it in a method that I missed somewhere?
And how would I interface the textgrid with a non-applet program? I can't seem to get it to display in a frame or pane. The pane.add() method doesn't seem to take effect.
Also, do the different cells have coordinates that can be displayed and used as variables when the individual cells are accessed?
.. it is/runs as - an application when started from the console. If you
embed it in a web page it runs as an applet. I usually do it like this
when I make applets, its easier to trap bugs and run various tests.
Well.
How do I specify the number of rows and columns, is it in a method that I missed somewhere
Its done in the getParameter method in TextGrid, I have restructured it here
so its more clear what happends, - this method is invoked in the init method
like:
//Get a parameter value
public String getParameter(String key, String def) {
if (isStandalone) {
return System.getProperty(key, def); // APPLICATION MODE(will return def)
} else { // APPLET MODE
if (getParameter(key) != null) {
return getParameter(key); // parameter was included in applet tag
} else {
return def; // parameter not in applet tag, use default
}
}
}
So you set these values in the applet tag (named row_count & col_count)
and/or as the default ("10") in the calls from the init method. If you check out the static methods System.setProperty /System.getProperty
you will see yet another way
-----------------
And how would I interface the textgrid with a non-applet program? I can't seem to get it to display in a frame or pane. The pane.add() method doesn't seem to take effect
You see it all in the applets main() method. This is never invoked when
running in a browser;
So, being a hybrid it already is an application, but, in its application mode it treats the applet like a Panel. I'm not sure what kind
of pane you are trying to add it to (this is non-swing code).
------------------
do the different cells have coordinates that can be displayed and used as variables when the individual cells are accessed?
The GridCell is a Rectangle extension, so it has inherited the public
variables: x,y,width & height. These are the pixel position of the cell's
topLeft and its pixel width & height (see the call to the rectangle method setBounds in the constructor of GridCell).
GridCell is a java.awt.Rectangle (++)
The private variables rowNo & colNo are the grid-coordinates of the cell.
You can code set & get methods for those.
If you want to display their values you can make yourself another smaller
font and (in the draw method of GridCell) draw the values in one of the
cell's corners. This will involve a little xy tweaking that I leave up to you
No, do not mix awt & swing components. Rename all components in my source to
J<name> components (JApplet, JFrame), and change to the <name>.getContentPane().add(<component>)
way of adding components , - where it is required.
Bookmarks