Spag widgets

Hi naj,





I’ve been playing with the textfield & have come accross a problem & wonder if you have had the same problem? :?



Everything compiles to do with the widget & its listener, I can return the text I have set in it, but I can only partially edit the field itself - I can get a couple of backspaces in if I’m lucky - but I can’t type in the field at all.



I’ve used setEnabled(true) on the textfield in the code below with no luck.

I can’t see what is wrong unless it is the component itself & I checked the source & can’t see anything.

:?



public class SpagTest20 extends AbstractGame implements GroupButtonListener, EditorListener, OKCancelListener
{
.
.
.
.

   public void createWin2() throws Exception
   {
       //F2 GUI - checkboxes, buttons, fields.
        w2 = new net.puppygames.gui.Window("F2 Spag window");
        w2.setLocation(50, 50);
        w2.setSize(500, 300);

      okCancelPanel = new OKCancelPanel();
       okCancelPanel.addOkCancelListener(this);

      //set up input field + label
      nameLabel = new Label("Enter name");
        nameField = new TextField(20);
      nameLabel.setLocation(50,150).layout().pack().setWidth(100);
        nameField.setLocation(150,150).layout().pack().setWidth(100);
      nameField.addEditorListener(this);
      nameField.setText("Type here");

      //setup checkboxes
      checkBox1 = new CheckBox("One");
        checkBox2 = new CheckBox("Two");
      checkBox1.setLocation(50,100).layout().pack().setWidth(100);
        checkBox2.setLocation(50,75).layout().pack().setWidth(100);
      checkBox1.addGroupButtonListener(this);   
      checkBox2.addGroupButtonListener(this);   

      w2.addChild(nameLabel);
        w2.addChild(nameField);
      w2.addChild(checkBox1);
        w2.addChild(checkBox2);
       w2.addChild(okCancelPanel);
        okCancelPanel.layout();

      w2.setDraggable(true);
        w2.open();

      //hide window
      w2.setVisible(false);
   }


   //for TextField
   public boolean editChanged(Editor source, int key)
   {
        if(source == nameField)
       {
      //do something with text input
       }

      return false;
   }


   //OK button listener on OKCancelPanel
   public void okClicked()
   {
       System.out.println(nameField.getText());
      enablePlayMode();   
      w2.setVisible(false);
   }


   //Cancel button listener on OKCancelPanel
   public void cancelClicked()
   {
       // does the same as OK at the moment
        enablePlayMode();   
      w2.setVisible(false);
   }


   //listen for checkbox events in createWin2()
   public boolean groupButtonChanged(GroupButton but, boolean sel)
   {
       if(but == checkBox1 && sel == true) System.out.println("checkBox1 is checked!!");
      else if (but == checkBox2 && sel == true) System.out.println("checkBox2 is checked!!");
      return false;
   }

.
.
.
.
}






I've had alook in CVS this morning to see if spag has been updated & it hasn't yet. I assume any new version will use lwjgl 0.8. :)

i am running late for a meeting, but have you tried adding a FocusListener to the textfield so that the keyboard knows it has focus to add the text to? i dont know if that would work, but who knows :smiley: i will play with it some tonight if that is no help.

I hope I’m reading the source right, but I think a a focuslistener is added in the source for TextField so it should already be about.



I’ve changed my render() method also so Keyboard.poll(); & Keyboard.read(); now happen in guiMode in update() instead but this has no effect.



What I can’t understand is how the keyboard responds to the odd backspace but nothing else.



I would of thought without any eventListeners you should be able to just type in the field, a bit like TextField in awt or JTextField in Swing I think. I’m going to take the eventlisteners out from textfield & if this doesn’t work then something a bit more serious may be needed.



I’ll get back when I’ve done this.

Nope didn’t work.



I can’t see what I could be doing wrong.



Must be the actual class or perhaps some performance problem on my machine. :? I’m still using lwjgl 0.7.

Fixed it :smiley:



When you are initing your Keyboard I bet you are forgeting to enable translation…



        Keyboard.create();
        Keyboard.enableBuffer();
        Keyboard.enableTranslation();



all i did for the textfield was this (no listeners or anything)...


        TextField nameField = new TextField(30);
        nameField.setLocation(15, 100).layout().pack().setWidth(100);
        nameField.setText("Type here");

Thanks :smiley:



I must admitt I was looking at the lwjgl Keyboard class as possible culprit as the mouse was working fine (you create the mouse with AbsMouse in SPGL) & was wondering about the keyboard.



I’d only got as far as thinking about changing the position of poll() + create(), etc… rather than add stuff in systemInit() - so thanks again. :slight_smile:



I really ought to learn lwjgl/OpenGL properly. ://





_______________________________________







Have you seen princec’s remarks reagrding spag 2.0 over on tour last thread on puppygames?





The new Spaghetti is completely rewritten from the ground up and comparable in compatibility like Windows is compatible with a Texas Instruments Speak and Spell.

However, the current version in CVS more or less works I believe, so if you want to get something working in it... that's what to aim for. I'm only going to fill in bits of Spaghetti "2.0" as and when I need them.



May be worth considering adding more stuff for JME purposes, but by then it may have most things we may need (!)

yeah i saw that… not real sure what he means… is he saying that he is not going to put it out there until he needs a piece here and there? if that is the case, i might just start rewriting it to fit mojo’s style, make it WAY more intutive, and then contribute it to jme.

Yes that may be a good idea, to as soon as he has posted the v2.0 framework, try & work in as much stuff that shares the same sort of fuctionality as awt/swing widgets and events + would be useful to JME.



To have documentation in the javadocs would be really cool as well :wink: :slight_smile:



I think he is only going to add stuff he uses in Alien Flux & then any other games he uses so it won’t necassarily be a full GUI API.



I have spotted some things in the current version which I don’t think he uses in Alien Flux - Radiobuttons spring to mind. I’m not sure all the current spag 1.0 classes are full with the intended content as it was probably not needed.

Just to tell you the change you suggested I just tried & it did work, but the text appeared very slowly and with constant presses, but I looked in the code & realised using Keyboard.poll(); & read(); in update() must be confusing/slowing stuff down as I assume now Textfield has all this Keyboard stuff set in its class. So anyway I took it out & it works fine now.



Thought I better let you know.





I really ought to learn lwj…

i guess i missed that you were calling Keyboard.read()… that sound like some kind of old c-ish getch() function :slight_smile: glad it is working now