AutoHotkey
Code:
InputBox, name, Hello Ubuntu, Please enter your name.
MsgBox, Hello %name%! Welcome to Ubuntu!
-----
and more Java variations...
Java 1.6 Swing
Code:
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class HelloUbuntuSwing extends JFrame {
public JPanel panel;
public JLabel label;
public JTextField area;
public JButton go;
public JTextArea output;
public HelloUbuntuSwing() {
setTitle("Hello Ubuntu");
setPreferredSize(new Dimension(400, 300));
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel = new JPanel();
setContentPane(panel);
init();
setLayout();
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private void init() {
label = new JLabel("Hi! What's your name?");
area = new JTextField(10);
go = new JButton("Submit!");
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = area.getText();
if(name.equals("")) JOptionPane.showMessageDialog(null, "Please enter your name.");
else {
String format = "Hello %s! Welcome to Ubuntu!";
output.setText(String.format(format, name));
}
}
});
output = new JTextArea();
output.setColumns(20);
output.setRows(3);
}
private void setLayout() {
add(label);
add(area);
add(go);
add(output);
}
public static void main(String[] args) {
new HelloUbuntuSwing();
}
}
Java 1.6 Using SwiXML GUI
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.swixml.SwingEngine;
public class HelloUbuntu {
public JFrame frame;
public JTextField input;
public JButton go;
public JTextArea output;
public HelloUbuntu() throws Exception {
new SwingEngine(this).render(new File("hello.xml"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = input.getText();
if(name.equals("")) JOptionPane.showMessageDialog(null, "Please enter your name.");
else {
String format = "Hello %s! Welcome to Ubuntu!";
output.setText(String.format(format, name));
}
}
});
output.setLineWrap(true);
output.setWrapStyleWord(true);
}
public static void main(String[] args) throws Exception {
new HelloUbuntu();
}
}
"hello.xml"
Code:
<frame id='frame' title="Hello Ubuntu!">
<panel layout='GridLayout(1,2)'>
<panel layout='GridLayout(3,1)'>
<label>Hello! What's your name?</label>
<textfield id='input' columns="10"/>
<button id='go'>Submit!</button>
</panel>
<panel><textarea id='output' columns="12" rows="3"/></panel>
</panel>
</frame>
Bookmarks