Nice TWiki > Doc > CodeExamples > HelloSwingWorld (r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
This example shows how to write a little more than a simple helloworld. When you move the mouse over the (inner part of the) Frame it will say hello, when you move out it will say goodbye :-)
import nice.ui.common;

void main(String[] args) 
{ 
  String greeting = "";
  NPanel panel = new NPanel
    (paintComponent: (java.awt.Graphics g) => { g.setColor(java.awt.Color.blue); g.drawString(greeting,5,40); },
     mouseEntered: (java.awt.event.MouseEvent e) => { greeting = "Hello Nice World"; },
     mouseExited: (java.awt.event.MouseEvent e) => { greeting = "  Bye Nice World"; } 
     ); panel.init();
  new NFrame(content: panel).init();
}
Note that in the Nice version you don't have to derive a new class from panel for overriding paintComponent. This would be necessary in Java ! I don't know how many lines one would have to write in Java to achieve this "functionality" but I guess more than 12 (well formatted) of them :-)

-- GamsL - 31 Jul 2002

The short version (just displaying a label saying helloworld) is:

import nice.ui.common;

void main(String[] args) { new NFrame(content: makeJLabel(text: "Hello World")).init(); }
-- GamsL - 01 Aug 2002

This code does not compile anymore: I don't see NPanel anywhere. Can somebody update this example?

-- DanielBonniot - 30 May 2003

Topic HelloSwingWorld . { Edit | Attach | Ref-By | Printable | Diffs | r1.6 | > | r1.5 | > | r1.4 | More }
Revision r1.2 - 30 May 2003 - 15:40 GMT - DanielBonniot
Parents: WebHome > CodeExamples
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.