复制
收藏
提问
简洁

import javax.swing.*; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Font; import javax.swing.ImageIcon; import javax.swing.JButton; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class DetailedContinentOceanQuery extends JFrame { private static JPanel panel; private JComboBox<String> continentComboBox; private JComboBox<String> oceanComboBox; private JLabel continentDetailLabel; private JLabel oceanDetailLabel; private JTextArea continentDetailTextArea; private JTextArea oceanDetailTextArea; private JLabel imageLabel; private JButton clearButton; private JPanel bottomPanel; public DetailedContinentOceanQuery() { setTitle("七大洲四大洋详细查询"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(734, 582); setLocationRelativeTo(null); panel = new JPanel(new GridLayout(4, 2)); String[] continents = {"亚洲", "欧洲", "非洲", "北美洲", "南美洲", "大洋洲", "南极洲"}; continentComboBox = new JComboBox<>(continents); continentComboBox.setFont(new Font("宋体", Font.PLAIN, 14)); continentComboBox.addActionListener(e -> { String selectedContinent = (String) continentComboBox.getSelectedItem(); displayContinentDetails(selectedContinent); }); String[] oceans = {"太平洋", "大西洋", "印度洋", "北冰洋"}; oceanComboBox = new JComboBox<>(oceans); oceanComboBox.setFont(new Font("宋体", Font.PLAIN, 14)); oceanComboBox.addActionListener(e -> { String selectedOcean = (String) oceanComboBox.getSelectedItem(); displayOceanDetails(selectedOcean); }); continentDetailLabel = new JLabel("大洲详情:"); continentDetailLabel.setFont(new Font("宋体", Font.BOLD, 16)); continentDetailLabel.setForeground(Color.BLUE); oceanDetailLabel = new JLabel("大洋详情:"); oceanDetailLabel.setFont(new Font("宋体", Font.BOLD, 16)); oceanDetailLabel.setForeground(Color.BLUE); continentDetailTextArea = new JTextArea(); continentDetailTextArea.setEditable(false); continentDetailTextArea.setLineWrap(true); continentDetailTextArea.setFont(new Font("宋体", Font.PLAIN, 14)); oceanDetailTextArea = new JTextArea(); oceanDetailTextArea.setEditable(false); oceanDetailTextArea.setLineWrap(true); oceanDetailTextArea.setFont(new Font("宋体", Font.PLAIN, 14)); JScrollPane continentScrollPane = new JScrollPane(continentDetailTextArea); JScrollPane oceanScrollPane = new JScrollPane(oceanDetailTextArea); JLabel label = new JLabel("选择大洲:"); label.setFont(new Font("新宋体", Font.PLAIN, 14)); panel.add(label); panel.add(continentComboBox); JLabel label_1 = new JLabel("选择大洋:"); label_1.setFont(new Font("宋体", Font.PLAIN, 14)); panel.add(label_1); panel.add(oceanComboBox); panel.add(continentDetailLabel); panel.add(oceanDetailLabel); getContentPane().add(panel, BorderLayout.NORTH); JPanel detailPanel = new JPanel(new GridLayout(1, 2)); detailPanel.add(continentScrollPane); detailPanel.add(oceanScrollPane); getContentPane().add(detailPanel, BorderLayout.CENTER); imageLabel = new JLabel(); getContentPane().add(imageLabel, BorderLayout.SOUTH); bottomPanel = new JPanel(); clearButton = new JButton("清空"); clearButton.setFont(new Font("宋体", Font.PLAIN, 14)); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { continentDetailTextArea.setText(""); oceanDetailTextArea.setText(""); imageLabel.setIcon(null); } }); bottomPanel.add(clearButton); getContentPane().add(bottomPanel, BorderLayout.SOUTH); } private void displayContinentDetails(String selectedContinent) { String continentDetail = ""; switch (selectedContinent) { case "亚洲": continentDetail = "亚洲是世界上面积最大的大洲,其面积约为 4457.9 万平方千米。亚洲东部和南部是世界上季风气候最显著的地区,拥有多样的文化和丰富的资源。亚洲地形的总特点是地势高、地表起伏大,中间高、周围低,隆起与凹陷相间,东部有一列纵长的花彩状岛弧。平均海拔约 950

fef5fd1ff
2个月前
全网
文档
学术
百科
知识库
时间不限
自动
回答简洁模式
深入研究一些

看起来你正在编写一个Java Swing应用程序,用于查询七大洲和四大洋的详细信息。你的代码已经实现了基本的界面布局和一些功能,但是displayContinentDetails方法中的switch语句并没有完成,并且缺少了displayOceanDetails方法的实现。

我可以帮你完成displayContinentDetails方法的剩余部分,并添加displayOceanDetails方法的示例实现。以下是可能的实现方式:

// 继续displayContinentDetails方法
... // 你已经写了一部分
	            case "欧洲":
	                continentDetail = "欧洲是世界第二小的大洲,面积约为1018万平方千米。欧洲有着丰富的历史和文化遗产,气候多样,从北极的寒冷气候到地中海的温和气候。";
	                break;
	            case "非洲":
	                continentDetail = "非洲是世界第二大的大洲,面积约为30,370,000平方千米。非洲以其野生动物和多样的生态系统而闻名,气候从撒哈拉沙漠的极端干旱到热带雨林的湿润。";
	                break;
	            // 继续为其他大洲添加case
	            default:
	                continentDetail = "未知大洲";
	                break;
	        }
	        continentDetailTextArea.setText(continentDetail);

	    private void displayOceanDetails(String selectedOcean) {
	        String oceanDetail = "";

	        switch (selectedOcean) {
	            case "太平洋":
	                oceanDetail = "太平洋是世界上最大的海洋,面积约为165,250,000平方千米。它横跨南北半球,连接亚洲、大洋洲、南美洲和北美洲。";
	                break;
	            case "大西洋":
	                oceanDetail = "大西洋是世界第二大海洋,面积约为106,460,000平方千米。它连接欧洲、非洲、南美洲和北美洲。";
	                break;
	            case "印度洋":
	                oceanDetail = "印度洋是世界第三大海洋,面积约为68,556,000平方千米。它位于亚洲、非洲、大洋洲和南极洲之间。";
	                break;
	            case "北冰洋":
	                oceanDetail = "北冰洋是世界最小的海洋,面积约为14,060,000平方千米。它位于北极地区,大部分被冰覆盖。";
	                break;
	            default:
	                oceanDetail = "未知大洋";
	                break;
	        }
	        oceanDetailTextArea.setText(oceanDetail);
	    }

请注意,这些详细信息只是示例,你可以根据需要添加更多的信息或者调整文本内容。此外,你可能还需要考虑如何处理用户选择一个不存在的选项的情况,我在default分支中添加了相应的处理。

如果你需要进一步的帮助,比如添加图片显示功能或者其他功能,请随时告诉我。

你觉得结果怎么样?
Java Swing 布局管理器有哪些?
JComboBox 如何添加事件监听器?
如何在 Java Swing 中使用 JScrollPane?
Java Swing 中的 ActionListener 接口是什么?
如何设置 JTextArea 的只读属性?
Java Swing 应用程序如何设置窗口关闭操作?

以上内容由AI搜集生成,仅供参考

在线客服