java - Writing with one button -


i in school got tasked invent solution writing 1 button on keyboard. main task writing report it, requires make prototype. that's stuck. have made javafx buttons a-å(norwegian letters), , plan pick random button (say g-key on keyboard) , each push move next letter. on double click on button should print out letter text box, , next click move on next letter in line. way should able write simple text messages.

i stuck right on how make "g-key" switch different buttons, , how make print out text field. new programming , javafx, , apologizes stupid question. not sure if javafx simplest way this, choose because familiar it.

my code far: sample.fxml:

    <gridpane fx:controller="sample.controller"           xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">             <textfield gridpane.columnindex="1" gridpane.rowindex="1"/>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="2">         <button text="a" fx:id="pushed" onaction="#write"/>         <button text="b" />         <button text="c"/>         <button text="d"/>         <button text="e"/>     </hbox>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="3">         <button text="f"/>         <button text="g"/>         <button text="h"/>         <button text="i"/>         <button text="j"/>         <button text="k"/>     </hbox>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="4"></hbox>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="5">         <button text="r"/>         <button text="s"/>         <button text="t"/>         <button text="u"/>         <button text="v"/>         <button text="x"/>     </hbox>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="6">         <button text="y"/>         <button text="z"/>         <button text="Æ"/>         <button text="Ø"/>         <button text="Å"/>     </hbox>     <hbox spacing="10" alignment="bottom_right"           gridpane.columnindex="1" gridpane.rowindex="7">         <button text="space"/>         <button text="."/>     </hbox> </gridpane> 

controller.java:

package sample;  import javafx.event.actionevent; import javafx.fxml.fxml;  public class controller {      public void write(actionevent event){      } } 

main.java:

package sample;  import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.scene.parent; import javafx.scene.scene; import javafx.stage.stage;  public class main extends application {      @override     public void start(stage primarystage) throws exception{         parent root = fxmlloader.load(getclass().getresource("sample.fxml"));         primarystage.settitle("hello world");         primarystage.setscene(new scene(root, 300, 275));         primarystage.show();     }       public static void main(string[] args) {         launch(args);     } } 

here sample app can play with. didn't implement backspace, tab, enter etc. didn't test app see if correctly handled restarting character cycle after going through of characters. should starting point. in app, coded change of character on single click, , append text textfield on double click. how detect double click came @jamesd answer here.

import java.util.arraylist; import java.util.list; import javafx.animation.pausetransition; import javafx.application.application; import javafx.beans.property.integerproperty; import javafx.beans.property.simpleintegerproperty; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.textarea; import javafx.scene.layout.stackpane; import javafx.scene.layout.vbox; import javafx.stage.stage; import javafx.util.duration;  /**  *  * @author blj0011  */ public class onebuttonwriter extends application {      final static string alphabets = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123456789;~!@#$%^&*()_+~!@#$%^&*()_+[]\\{}|;':\",./<>?";     final static string[] action_keys = {"tab", "enter"};      list<string> keys = new arraylist();//holds each key      int currentkey = 0;      @override     public void start(stage primarystage) {         loadkeys();//add keys alphabets , action_keys keys arralist individual keys.          textarea textarea = new textarea();          button button = new button();          //code jame_d answer on double click         duration maxtimebetweensequentialclicks = duration.millis(500);          pausetransition clicktimer = new pausetransition(maxtimebetweensequentialclicks);         final integerproperty sequentialclickcount = new simpleintegerproperty(0);         clicktimer.setonfinished(event -> {             int count = sequentialclickcount.get();             if (count == 1)             {                 system.out.println("single click");                 textarea.appendtext(button.gettext());//if single click append text textarea             }             if (count == 2)             {                 system.out.println("double click");                 currentkey++;//if double click increment currentkey                 if(currentkey == keys.size())//if currentkey equal keys size set current key or index 0 ***i have not tested this***                 {                     currentkey = 0;                 }                  button.settext(keys.get(currentkey));             }             if (count == 3) system.out.println("triple click");             if (count > 3) system.out.println("multiple click: "+count);             sequentialclickcount.set(0);         });           button.setprefsize(100, 100);         button.settext(keys.get(currentkey));         button.setonmouseclicked(event -> {                         sequentialclickcount.set(sequentialclickcount.get()+1);             clicktimer.playfromstart();          });          vbox vbox = new vbox();         vbox.getchildren().add(textarea);         vbox.getchildren().add(new stackpane(button));          stackpane root = new stackpane();         root.getchildren().add(vbox);          scene scene = new scene(root, 300, 250);          primarystage.settitle("hello world!");         primarystage.setscene(scene);         primarystage.show();     }      /**      * @param args command line arguments      */     public static void main(string[] args) {         launch(args);     }      private void loadkeys()     {         for(int = 0; < alphabets.length(); i++)         {             keys.add(character.tostring(alphabets.charat(i)));         }          for(string actionkey : action_keys)         {             keys.add(actionkey);         }     }  } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -