Nice TWiki > Doc > CodeExamples > HelloSwingWorld (r1.4) 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;

import javax.swing.*;

class HelloPanel extends JPanel
{
  private String greeting;
  void setGreeting(String);
}

paintComponent(HelloPanel panel ,g) 
{ 
  super;
  g.setColor(java.awt.Color.blue); 
  g.drawString(panel.greeting,5,40); 
}
   
setGreeting(HelloPanel panel, s) 
{ 
  this.greeting = s; 
  this.repaint(); 
}

void main(String[] args) 
{ 
  HelloPanel panel = new HelloPanel(greeting:"come inside");
  panel.init

    (mouseEntered: (java.awt.event.MouseEvent e) => { panel.setGreeting("Hello Nice World"); },
     mouseExited: (java.awt.event.MouseEvent e) => { panel.setGreeting("  Bye Nice World"); } 
     );

  
  JFrame frame = new JFrame("Hello Nice World").init
    (windowClosing: java.awt.event.WindowEvent e => System.exit(0)
     );
  
  frame.getContentPane().add(panel);
  frame.setSize(100,100);
  frame.show();
}

Topic HelloSwingWorld . { Edit | Attach | Ref-By | Printable | Diffs | r1.6 | > | r1.5 | > | r1.4 | More }
Revision r1.4 - 23 Jan 2005 - 13:50 GMT - TWikiGuest
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.