The Java Version

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

class MyFrame extends JFrame{ public MyFrame(){

JButton sayHello;opment.

sayHello = new JButton("say hello");

sayHello.setMnemonic('h');

this.getContentPane().add(sayHello);

this.setVisible(true) ;

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");

Here's the JavaScript (Rhino at JavaScript 1.4) version.

function MyFrame(){

sayHello = new Packages.javax.swing.JButton("say hello");

sayHello.setMnemonic('h') ;

this.frame = new Packages.javax.swing.JFrame();

this.f rame.getContentPane() .add(sayHello); this.frame.setVisible(true) ; this.f rame.pack() ;

sayHello.addActionListener( new Packages.j ava.awt.event.ActionListen

_parent_ : this, actionPerformed : function(ae) { ae.getSource().setEnabled(false);

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.frame.setTitle("My Hello"); }

Was this article helpful?

0 0

Post a comment