001package org.vishia.gral.test; 002 003import org.vishia.gral.base.GralButton; 004import org.vishia.gral.base.GralMng; 005import org.vishia.gral.base.GralPanelContent; 006import org.vishia.gral.base.GralWindow; 007import org.vishia.gral.ifc.GralUserAction; 008import org.vishia.gral.ifc.GralWidget_ifc; 009import org.vishia.gral.widget.GralLabel; 010import org.vishia.msgDispatch.LogMessage; 011import org.vishia.msgDispatch.LogMessageStream; 012import org.vishia.util.KeyCode; 013 014 015/*Test with jzcmd: call jzcmd with this java file with its full path: 016D:/vishia/Java/srcJava_vishiaGui/org/vishia/gral/test/HelloWorld.java 017==JZcmd== 018java org.vishia.gral.test.HelloWorld.main(null); 019==endJZcmd== 020 */ 021 022 023public class HelloWorld 024{ 025 String[] helloText = { "hello user", "hello world"}; 026 027 GralUserAction actionTestButton = new GralUserAction("TestButton") { 028 @Override public boolean exec(int key, GralWidget_ifc widgi, Object...args) { 029 if(KeyCode.isControlFunctionMouseUpOrMenu(key)) { 030 widgHelloText.setText("hello again"); 031 } 032 return true; 033 } 034 }; 035 036 /**The GralWindow have to be initialized firstly, after them the widgets in the window. Therewith the assignment of the widgets to this window 037 * is determined. The widgets are created with the window then, see {@link GralPanelContent#createImplWidget_Gthread()} 038 */ 039 GralWindow window = new GralWindow("50+30, 50+50", "HelloWorldWind", "Simple Hello World application", GralWindow.windResizeable + GralWindow.windHasMenu); 040 GralLabel widgHelloText = new GralLabel("3-2,2+5", "HelloLabel", helloText[0], 0); 041 GralButton widgButton = new GralButton("7-3,10+12", "TestButton", "press me", actionTestButton); 042 043 044 public static void main(String[] args){ 045 HelloWorld main = new HelloWorld(); 046 String sTypeOfImplementation = "AWT"; //default 047 if(args.length >=1){ 048 sTypeOfImplementation = args[0]; 049 } 050 LogMessage log = new LogMessageStream(System.out); //a logging system. 051 main.window.create(sTypeOfImplementation, 'C', log, null); //creates the primary window, starts the whole graphic engine. 052 //wait, a parallel thread to the grahic. 053 main.doSomethinginMainthreadTillClosePrimaryWindow(); 054 } 055 056 057 058 059 public void doSomethinginMainthreadTillClosePrimaryWindow() 060 { int ix = 0; 061 while(GralMng.get().gralDevice.isRunning()){ 062 try{ Thread.sleep(2000);} 063 catch (InterruptedException e) { } 064 if(++ix >= helloText.length) { ix = 0; } 065 widgHelloText.setText(helloText[ix]); 066 } 067 068 } 069 070 071}