用Java Swing实现海洋旅游景点导航系统的景点详情界面
时间: 2024-03-08 11:50:31 浏览: 23
好的,下面是一个简单的Java Swing实现海洋旅游景点导航系统的景点详情界面的示例代码:
```java
import javax.swing.*;
import java.awt.*;
public class SpotDetails extends JFrame {
private JLabel nameLabel, locationLabel, descriptionLabel, imageLabel;
private JTextArea descriptionArea;
public SpotDetails() {
// 设置窗口标题和大小
setTitle("景点详情");
setSize(400, 500);
// 创建面板
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
// 创建标签和文本框
nameLabel = new JLabel("名称:XXX");
locationLabel = new JLabel("地点:XXX");
descriptionLabel = new JLabel("介绍:");
descriptionArea = new JTextArea(10, 20);
descriptionArea.setLineWrap(true);
descriptionArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(descriptionArea);
imageLabel = new JLabel(new ImageIcon("spot.jpg"));
// 添加标签和文本框到面板
panel.add(nameLabel);
panel.add(locationLabel);
panel.add(descriptionLabel);
panel.add(scrollPane);
panel.add(imageLabel);
// 设置面板边框和空白区域
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// 将面板添加到窗口中并设置可见性
add(panel);
setVisible(true);
}
public static void main(String[] args) {
new SpotDetails();
}
}
```
在这个示例代码中,我们创建了一个`JFrame`窗口和一个`JPanel`面板,然后在面板中添加了标签、文本框和图片等组件。其中,标签和文本框用于展示景点的名称、地点和介绍等信息,图片用于展示景点的照片。我们还为介绍文本框添加了一个滚动条,以便在文本内容过长时能够自动显示滚动条。
您可以根据实际需求来修改和完善这个示例代码,例如根据不同的景点动态加载不同的图片和介绍信息等。