请用Java写一个Windows用户界面
时间: 2024-05-13 15:16:42 浏览: 13
很高兴为您回答问题。 我可以为您提供一个简单的Java代码来创建一个Windows用户界面。以下是代码:
```java
import javax.swing.*;
import java.awt.*;
public class MyGUI extends JFrame {
// create the GUI elements
private JLabel label = new JLabel("Hello, World!");
private JButton button = new JButton("Click me!");
public MyGUI() {
// set the window properties
setTitle("My Window");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setLocationRelativeTo(null);
// add the elements to the window
setLayout(new FlowLayout());
add(label);
add(button);
// show the window
setVisible(true);
}
public static void main(String[] args) {
// create the GUI object
MyGUI gui = new MyGUI();
}
}
```
这个代码使用Java Swing库创建一个简单的窗口,里面有一个标签和一个按钮。您可以根据需要添加其他 GUI 元素。希望这对您有所帮助。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)