hello world程序集锦(6)

C 和 GTK+

#include <gtk/gtk.h>

int main(int argc, char * args[])
{
 GtkWidget * win, * label;
 gtk_init(& argc, & args);

 label = gtk_label_new("Hello, world!");
 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_container_add(GTK_CONTAINER(win), label);
 gtk_widget_show_all();

 gtk_main();

 return 0;
}

用C++和gtkmm 2

#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm/button.h>
#include <gtkmm/window.h>
using namespace std;

class HelloWorld : public Gtk::Window 
{
public:
 HelloWorld();
 virtual ~HelloWorld();
protected:
 Gtk::Button m_button;
 virtual void on_button_clicked();
};

HelloWorld::HelloWorld() : m_button("Hello, world!")
{
 set_border_width(10);
 m_button.signal_clicked().connect(SigC::slot(*this, &HelloWorld::on_button_clicked));
 add(m_button);
 m_button.show();
}

HelloWorld::~HelloWorld() {}

void HelloWorld::on_button_clicked() 
{
 cout << "Hello, world!" << endl;
}

int main(int argc, char *argv[])
{
 Gtk::Main kit(argc, argv);
 HelloWorld helloworld;
 Gtk::Main::run(helloworld);
}

Java

import java.awt.*;
import java.awt.event.*;

public class HelloFrame extends Frame 
{
 HelloFrame(String title) 
 {
  super(title);
 }
 public void paint(Graphics g)
 {
  super.paint(g);
  java.awt.Insets ins = this.getInsets();
  g.drawString("Hello, World!", ins.left + 25, ins.top + 25);
 }
 public static void main(String args [])
 {
  HelloFrame fr = new HelloFrame("Hello");

  fr.addWindowListener(
   new WindowAdapter() 
   {
    public void windowClosing(WindowEvent e)
    {
     System.exit( 0 );
    }
   }
  );
  fr.setResizable(true);
  fr.setSize(500, 100);
  fr.setVisible(true);
 }
}

Java Applet

Java Applet用于HTML文件。

HTML代码:

<html>
<head>
<title>Hello World</title>
</head>
<body>
HelloWorld Program says:
<applet code="HelloWorld.class" width="600" height="100">
</applet>
</body>
</html>

Java代码:

import java.applet.*;
import java.awt.*;

public class HelloWorld extends Applet 
{
 public void paint(Graphics g) 
 {
  g.drawString("Hello, world!", 100, 50);
 }
}

JavaScript

JavaScript是一种脚本语言。最广泛用于HTML文件中,也可以用在其它宿主环境下,比如Microsoft Windows 脚本宿主(WSH)和一些Web服务环境。

用于HTML中:

alert("Hello, World!");
//或者
document.write("Hello, World!");

用于WSH中:

WScript.Echo("Hello, World!");

PostScript

PostScript是一种专门用来创建图像的语言,常用于打印机。