June 2002
Beginner to intermediate
640 pages
14h 24m
English
To give you a feel for scripting, we're going to compare how it's done in three languages, Java, JavaScript, and Python. We'll make the comparison more interesting by adding a Say Hello button, which when pressed causes a window to pop up and display “Hello World” in 18-point bold type.
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); ...Read now
Unlock full access