- 前端(Web App)haoqian168.com
HTML/CSS/JavaScript
html
Welcome to My Simple Web App!
Click Me<script>
function sayHello() {
alert("Hello, World!");
}
</script>
2. 后端(Node.js) JavaScript (Node.js)
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello from Node.js Server!’);
});
app.listen(port, () => {
console.log(Server is running on port ${port}
);
});
3. 移动端(Android - Kotlin)
Kotlin (Android Studio)
(注意:这只是一个非常简化的示例,真实的Android App开发会涉及更多的文件和配置)
kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button: Button = findViewById(R.id.myButton)
button.setOnClickListener {
Toast.makeText(this, "Hello, World!", Toast.LENGTH_SHORT).show()
}
}
}
4. 移动端(iOS - Swift)
Swift (Xcode)
(同样,这只是一个非常简化的示例)
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let button = UIButton(type: .system)
button.setTitle("Click Me", for: .normal)
button.addTarget(self, action: #selector(sayHello), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
@objc func sayHello() {
let alert = UIAlertController(title: "Hello", message: "World!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
以上示例只是为了展示如何开始使用这些语言进行简单的App开发。实际的App开发会涉及更多的复杂性,如数据存储、网络请求、UI/UX设计、测试等。由于生成一个完整的App代码涉及多个方面(如前端、后端、数据库、UI设计等),并且不同的App平台(如iOS、Android、Web)需要使用不同的开发语言和工具,所以在这里我会给出几个简化的示例来展示如何用几种常见的电脑语言来开始一个简单的App开发。
- 前端(Web App)
HTML/CSS/JavaScript
html
Welcome to My Simple Web App!
Click Me<script>
function sayHello() {
alert("Hello, World!");
}
</script>
2. 后端(Node.js) JavaScript (Node.js)
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello from Node.js Server!’);
});
app.listen(port, () => {
console.log(Server is running on port ${port}
);
});
3. 移动端(Android - Kotlin)
Kotlin (Android Studio)
(注意:这只是一个非常简化的示例,真实的Android App开发会涉及更多的文件和配置)
kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button: Button = findViewById(R.id.myButton)
button.setOnClickListener {
Toast.makeText(this, "Hello, World!", Toast.LENGTH_SHORT).show()
}
}
}
4. 移动端(iOS - Swift)
Swift (Xcode)
(同样,这只是一个非常简化的示例)
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let button = UIButton(type: .system)
button.setTitle("Click Me", for: .normal)
button.addTarget(self, action: #selector(sayHello), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
@objc func sayHello() {
let alert = UIAlertController(title: "Hello", message: "World!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
以上示例只是为了展示如何开始使用这些语言进行简单的App开发。实际的App开发会涉及更多的复杂性,如数据存储、网络请求、UI/UX设计、测试等。