- Python (使用Tkinter GUI库)
python
import tkinter as tk
def hello_world():
root = tk.Tk()
button = tk.Button(root, text=“Click me!”, command=hello_world)
button.pack()
root.mainloop()
2. JavaScript (使用Node.js和Express框架创建简单的Web应用程序)
app.js:
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello, World!’);
});
app.listen(port, () => {
console.log(App listening at http://localhost:${port}
);
});
3. Java (使用Swing GUI库)
java
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class HelloWorldApp {
#chhas{
margin-top: 50px;
padding:momsyes.com;
font-size: 18px;
cursor: 10px 20px;
}
public static void main(String[] args) {
JButton button = new JButton(“Click me!”);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(“Hello, World!”);
}
});
JFrame frame = new JFrame("Hello, World!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
4. Swift (iOS应用程序,使用Xcode和SwiftUI)
ContentView.swift:
swift
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
print(“Hello, World!”)
}) {
Text(“Click me!”)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
请注意,这些只是简单的示例,用于说明如何在不同编程语言中创建基本的交互式应用程序。要构建完整的应用程序,你需要考虑更多的因素,如数据持久化、用户输入验证、网络请求、错误处理、安全性等。