HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Programming Languages for the JVM"
Volume: 5 Issue: 2, p.86

	

Listing 1: 

import javax.swing.*; 
import java.awt.Font; 
import java.awt.event.*; 

class MyFrame extends JFrame{ 
 public MyFrame(){ 
  JButton sayHello; 
  sayHello = new JButton("say hello"); 
  sayHello.setMnemonic('h'); 
  this.getContentPane().add(sayHello); 
  this.setVisible(true); 
  this.pack(); 

  sayHello.addActionListener(new ActionListener(){ 
   public void actionPerformed(ActionEvent ae){ 
    JButton b = (JButton)ae.getSource(); 
    b.setEnabled(false); 
    sayHello(); 
   } 
  }); 
 } 
 private void sayHello(){ 
  JFrame helloFrame; 
  JLabel helloLabel; 
  Font font; 
  helloFrame = new JFrame("Hello Frame"); 
  helloLabel= new JLabel("Hello World"); 
  font = new Font("Arial", Font.BOLD, 20); 
  helloLabel.setFont(font); 
  helloFrame.getContentPane().add(helloLabel); 
  helloFrame.pack(); 
  helloFrame.setVisible(true); 
 } 
 public static void main(String [] args){ 
  MyFrame frame = new MyFrame(); 
  frame.setTitle("My Frame"); 
 } 
} 

Listing 2: 

function MyFrame(){ 
 sayHello = new Packages.javax.swing.JButton("say hello"); 
  
 sayHello.setMnemonic('h'); 
 this.frame = new Packages.javax.swing.JFrame(); 

 this.frame.getContentPane().add(sayHello); 
 this.frame.setVisible(true); 
 this.frame.pack(); 
  
 sayHello.addActionListener( new Packages.java.awt.event.ActionListener() { 
  __parent__ : this, 
  actionPerformed : function(ae) { 
ae.getSource().setEnabled(false); 
   this.__parent__.sayHello(); 
  } 
 }); 
  
 function sayHello(){ 
  helloFrame = new Packages.javax.swing.JFrame("Hello Frame"); 
  helloLabel= new Packages.javax.swing.JLabel("Hello World"); 
  font = new java.awt.Font("Arial", java.awt.Font.BOLD, 20); 
  helloLabel.setFont(font); 
  helloFrame.getContentPane().add(helloLabel); 
  helloFrame.pack(); 
  helloFrame.setVisible(true); 
 } 
  
 this.sayHello=sayHello; 
} 

function main(){ 
 frame = new MyFrame(); 
 frame.frame.setTitle("My Hello"); 
} 
main(); 

Listing 3: 

from javax.swing import JFrame, JButton, JLabel 
from java.awt import Font 

class MyFrame (JFrame): 
 def __init__(self): 
  sayHello = JButton("say hello", mnemonic=ord('h')) 
  self.contentPane.add(sayHello) 
  self.visible=1 
  self.pack() 
  sayHello.actionPerformed = self.__sayHello 

 def __sayHello(self, ae): 
  ae.source.enabled=0 
  helloFrame = JFrame("Hello Frame") 
  helloLabel= JLabel("Hello World", font=Font("Arial", 
                   Font.BOLD, 20)) 
  helloFrame.contentPane.add(helloLabel) 
  helloFrame.pack() 
  helloFrame.visible=1 

if __name__=="__main__": 
  frame = MyFrame() 
  frame.title="My Frame" 



 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.