├── README.md ├── lib ├── flatlaf-3.2.jar └── mysql-connector-8.0.33.jar ├── src ├── Main.java ├── login_window.java ├── real_login.form ├── login_window.form ├── real_register.java ├── real_login.java ├── real_register.form └── EarthquakeMapApp.java ├── target └── classes │ ├── Main.class │ ├── login_window.class │ ├── real_login$1.class │ ├── real_login.class │ ├── login_window$1.class │ ├── login_window$2.class │ ├── real_register.class │ ├── EarthquakeMapApp.class │ ├── real_register$1.class │ ├── EarthquakeMapApp$1.class │ ├── EarthquakeMapApp$2.class │ ├── EarthquakeMapApp$3.class │ ├── EarthquakeMapApp$MapPanel.class │ ├── EarthquakeMapApp$GeoPosition.class │ ├── com │ └── intellij │ │ └── uiDesigner │ │ └── core │ │ ├── Util.class │ │ ├── Spacer.class │ │ ├── DimensionInfo.class │ │ ├── LayoutState.class │ │ ├── SupportCode.class │ │ ├── VerticalInfo.class │ │ ├── AbstractLayout.class │ │ ├── GridConstraints.class │ │ ├── HorizontalInfo.class │ │ ├── GridLayoutManager.class │ │ └── SupportCode$TextWithMnemonic.class │ └── EarthquakeMapApp$EarthquakeWaypoint.class ├── .idea ├── dataSources │ ├── ba1c374c-406d-4063-9e49-440e4cc70bd0 │ │ └── storage_v2 │ │ │ └── _src_ │ │ │ └── schema │ │ │ └── mysql.osA4Bg.meta │ └── ba1c374c-406d-4063-9e49-440e4cc70bd0.xml ├── vcs.xml ├── modules.xml ├── misc.xml ├── compiler.xml ├── jarRepositories.xml ├── dataSources.xml ├── dataSources.local.xml ├── uiDesigner.xml └── workspace.xml ├── earthquake_map_application.iml ├── .gitignore └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | 写得比较史,主要记录一下第一次java开发的过程 2 | -------------------------------------------------------------------------------- /lib/flatlaf-3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/lib/flatlaf-3.2.jar -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | login_window.main(); 4 | } 5 | } -------------------------------------------------------------------------------- /target/classes/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/Main.class -------------------------------------------------------------------------------- /lib/mysql-connector-8.0.33.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/lib/mysql-connector-8.0.33.jar -------------------------------------------------------------------------------- /target/classes/login_window.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/login_window.class -------------------------------------------------------------------------------- /target/classes/real_login$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/real_login$1.class -------------------------------------------------------------------------------- /target/classes/real_login.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/real_login.class -------------------------------------------------------------------------------- /target/classes/login_window$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/login_window$1.class -------------------------------------------------------------------------------- /target/classes/login_window$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/login_window$2.class -------------------------------------------------------------------------------- /target/classes/real_register.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/real_register.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp.class -------------------------------------------------------------------------------- /target/classes/real_register$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/real_register$1.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$1.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$2.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$3.class -------------------------------------------------------------------------------- /.idea/dataSources/ba1c374c-406d-4063-9e49-440e4cc70bd0/storage_v2/_src_/schema/mysql.osA4Bg.meta: -------------------------------------------------------------------------------- 1 | #n:mysql 2 | ! [0, 0, null, null, -2147483648, -2147483648] 3 | -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$MapPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$MapPanel.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$GeoPosition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$GeoPosition.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/Util.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/Util.class -------------------------------------------------------------------------------- /target/classes/EarthquakeMapApp$EarthquakeWaypoint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/EarthquakeMapApp$EarthquakeWaypoint.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/Spacer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/Spacer.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/DimensionInfo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/DimensionInfo.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/LayoutState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/LayoutState.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/SupportCode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/SupportCode.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/VerticalInfo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/VerticalInfo.class -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/AbstractLayout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/AbstractLayout.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/GridConstraints.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/GridConstraints.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/HorizontalInfo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/HorizontalInfo.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/GridLayoutManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/GridLayoutManager.class -------------------------------------------------------------------------------- /target/classes/com/intellij/uiDesigner/core/SupportCode$TextWithMnemonic.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bananashipsBBQ/earthquake_map_application_last/HEAD/target/classes/com/intellij/uiDesigner/core/SupportCode$TextWithMnemonic.class -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /earthquake_map_application.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306 9 | 10 | 11 | 12 | 13 | 14 | 15 | $ProjectFileDir$ 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/dataSources.local.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #@ 7 | ` 8 | true 9 | 10 | 11 | master_key 12 | root 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.dlnu.banana 7 | bananaships 8 | 1.0 9 | 10 | 11 | 17 12 | 17 13 | 14 | 15 | 16 | 17 | com.google.code.gson 18 | gson 19 | 2.8.8 20 | 21 | 22 | 23 | 24 | com.formdev 25 | flatlaf 26 | 3.2 27 | system 28 | E:/jvav_test/earthquake_map_application/lib/flatlaf-3.2.jar 29 | 30 | 31 | mysql 32 | mysql-connector-java 33 | 8.0.33 34 | system 35 | E:/jvav_test/earthquake_map_application/lib/mysql-connector-8.0.33.jar 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/login_window.java: -------------------------------------------------------------------------------- 1 | 2 | import javax.swing.*; 3 | import java.awt.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import com.formdev.flatlaf.FlatDarkLaf; 7 | public class login_window { 8 | private JPanel rootJpanel; 9 | private JPanel mainJpanel; 10 | private JPanel loginJpanel; 11 | private JButton registerButton; 12 | private JTextField usernameText; 13 | private JPasswordField passwordText; 14 | private JButton loginButton; 15 | private JPanel background; 16 | 17 | 18 | //private ImageIcon backgroundIcon; 19 | public login_window() { 20 | // 为登录按钮添加点击事件监听器 21 | //backgroundIcon = new ImageIcon("F:\\edge_downloads\\login_image.jpg"); 22 | loginButton.addActionListener(new ActionListener() { 23 | @Override 24 | public void actionPerformed(ActionEvent e) { 25 | real_login.main();//跳转到登录逻辑 26 | JFrame currentFrame = (JFrame) SwingUtilities.getWindowAncestor(rootJpanel); 27 | currentFrame.dispose();//关闭当前窗口 28 | } 29 | }); 30 | 31 | 32 | 33 | // 为注册按钮添加点击事件监听器 34 | registerButton.addActionListener(new ActionListener() { 35 | @Override 36 | public void actionPerformed(ActionEvent e) { 37 | // 这里是注册按钮的处理逻辑 38 | //JOptionPane.showMessageDialog(rootJpanel, "Navigating to Registration..."); 39 | // 注册按钮点击后跳转到注册界面 40 | real_register.main(); // 假设 RegisterWindow 是你注册的窗口 41 | JFrame currentFrame = (JFrame) SwingUtilities.getWindowAncestor(rootJpanel); 42 | currentFrame.dispose(); 43 | 44 | } 45 | }); 46 | 47 | 48 | } 49 | 50 | 51 | 52 | public static void main() { 53 | FlatDarkLaf.setup(); 54 | JFrame frame = new JFrame("login_window"); 55 | frame.setBounds(500, 500, 1500, 1500); 56 | frame.setContentPane(new login_window().rootJpanel); 57 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 58 | frame.pack(); 59 | frame.setVisible(true); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/real_login.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
64 | -------------------------------------------------------------------------------- /src/login_window.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
59 | -------------------------------------------------------------------------------- /src/real_register.java: -------------------------------------------------------------------------------- 1 | import com.formdev.flatlaf.FlatDarkLaf; 2 | 3 | import javax.swing.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.sql.*; 7 | 8 | public class real_register { 9 | 10 | private JButton registerButton; 11 | private JTextField textField1; 12 | private JPasswordField passwordField1; 13 | private JPasswordField passwordField2; 14 | private JPanel registerJpanel; 15 | static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; 16 | static final String DB_URL = "jdbc:mysql://localhost:3306/mysql"; 17 | static final String USER = "root"; 18 | static final String PASS = "123456"; 19 | 20 | public real_register() { 21 | registerButton.addActionListener(new ActionListener() { 22 | @Override 23 | public void actionPerformed(ActionEvent e) { 24 | 25 | String username1 = textField1.getText(); 26 | String password1 = new String(passwordField1.getPassword()); 27 | String password2 = new String(passwordField2.getPassword()); 28 | 29 | // 检查密码是否一致 30 | if (!password1.equals(password2)) { 31 | JOptionPane.showMessageDialog(registerJpanel, "密码不一致!请检查!"); 32 | return; 33 | } 34 | 35 | Connection conn = null; 36 | PreparedStatement pstmt = null; 37 | try { 38 | Class.forName(JDBC_DRIVER); // 注册 JDBC 驱动 39 | conn = DriverManager.getConnection(DB_URL, USER, PASS); // 连接数据库 40 | 41 | // 插入数据 42 | String sql = "INSERT INTO mapusers (username, password) VALUES (?, ?)"; 43 | pstmt = conn.prepareStatement(sql); 44 | pstmt.setString(1, username1); 45 | pstmt.setString(2, password1); 46 | int rows = pstmt.executeUpdate(); 47 | 48 | if (rows > 0) { 49 | JOptionPane.showMessageDialog(registerJpanel, "注册成功!"); 50 | login_window.main(); 51 | JFrame currentFrame = (JFrame) SwingUtilities.getWindowAncestor(registerJpanel); 52 | currentFrame.dispose(); 53 | } 54 | } catch (SQLException | ClassNotFoundException ex) { 55 | ex.printStackTrace(); 56 | JOptionPane.showMessageDialog(registerJpanel, "注册失败!"); 57 | } finally { 58 | try { 59 | if (pstmt != null) pstmt.close(); 60 | if (conn != null) conn.close();//关闭数据库链接 61 | } catch (SQLException se) { 62 | se.printStackTrace(); 63 | } 64 | } 65 | } 66 | }); 67 | } 68 | 69 | 70 | public static void main() { 71 | FlatDarkLaf.setup(); 72 | JFrame frame = new JFrame("real_register"); 73 | frame.setBounds(500, 500, 500, 500); 74 | frame.setContentPane(new real_register().registerJpanel); 75 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 76 | frame.pack(); 77 | frame.setVisible(true); 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/real_login.java: -------------------------------------------------------------------------------- 1 | import com.formdev.flatlaf.FlatDarkLaf; 2 | 3 | import javax.swing.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.sql.*; 7 | 8 | public class real_login { 9 | private JPanel panel1; 10 | private JTextField textField1; 11 | private JPasswordField passwordField1; 12 | private JButton realloginButton; 13 | static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; 14 | static final String DB_URL = "jdbc:mysql://localhost:3306/mysql"; 15 | static final String USER = "root"; 16 | static final String PASS = "123456"; 17 | 18 | public static boolean authenticate(String username, String password) { 19 | Connection conn = null; 20 | PreparedStatement pstmt = null; 21 | ResultSet rs = null; 22 | 23 | try { 24 | // 注册 JDBC 驱动 25 | Class.forName(JDBC_DRIVER); 26 | 27 | // 打开链接 28 | conn = DriverManager.getConnection(DB_URL, USER, PASS); 29 | 30 | // 准备 SQL 查询,查询数据库中的用户名和密码 31 | String sql = "SELECT * FROM mapusers WHERE username = ? AND password = ?"; 32 | pstmt = conn.prepareStatement(sql); 33 | pstmt.setString(1, username); 34 | pstmt.setString(2, password); 35 | 36 | // 执行查询 37 | rs = pstmt.executeQuery(); 38 | 39 | // 检查是否有匹配的结果 40 | return rs.next(); // 如果有结果,说明用户名和密码匹配 41 | } catch (SQLException | ClassNotFoundException e) { 42 | e.printStackTrace(); 43 | } finally { 44 | // 关闭资源 45 | try { 46 | if (rs != null) rs.close(); 47 | if (pstmt != null) pstmt.close(); 48 | if (conn != null) conn.close(); 49 | } catch (SQLException se) { 50 | se.printStackTrace(); 51 | } 52 | } 53 | 54 | return false; 55 | } 56 | 57 | public real_login(){ 58 | // 为登录按钮添加点击事件监听器 59 | realloginButton.addActionListener(new ActionListener() { 60 | @Override 61 | public void actionPerformed(ActionEvent e) { 62 | // 这里是登录按钮的处理逻辑 63 | String username = textField1.getText(); 64 | String password = new String(passwordField1.getPassword()); 65 | // 判断用户名和密码,假设验证通过跳转到登录成功的窗口 66 | if (authenticate(username, password)) { 67 | JOptionPane.showMessageDialog(panel1, "登录成功!"); 68 | // 登录成功后可以跳转到主界面 69 | // 假设 MainWindow 是你跳转后的窗口 70 | EarthquakeMapApp.main(null); 71 | JFrame currentFrame = (JFrame) SwingUtilities.getWindowAncestor(panel1); 72 | currentFrame.dispose();//关闭当前窗口 73 | } else { 74 | JOptionPane.showMessageDialog(panel1, "登录失败!"); 75 | } 76 | } 77 | }); 78 | } 79 | 80 | 81 | public static void main() { 82 | FlatDarkLaf.setup(); 83 | JFrame frame = new JFrame("real_login"); 84 | frame.setBounds(500, 500, 500, 500); 85 | frame.setContentPane(new real_login().panel1); 86 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 87 | frame.pack(); 88 | frame.setVisible(true); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/real_register.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/EarthquakeMapApp.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | import java.awt.event.*; 4 | import java.awt.geom.Point2D; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | import java.io.BufferedReader; 10 | import java.io.InputStreamReader; 11 | import com.google.gson.JsonArray; 12 | import com.google.gson.JsonElement; 13 | import com.google.gson.JsonParser; 14 | import javax.imageio.ImageIO; 15 | import java.io.File; 16 | import java.io.IOException; 17 | 18 | public class EarthquakeMapApp { 19 | 20 | private JFrame frame; 21 | private JPanel mapPanel; 22 | private JTextArea earthquakeInfoArea; 23 | private List waypoints; 24 | private double zoomLevel = 1.0; // 初始缩放级别,1.0为正常尺寸 25 | private double mapCenterX = 0.0; // 地图中心X坐标(经度) 26 | private double mapCenterY = 0.0; // 地图中心Y坐标(纬度) 27 | 28 | private Image earthImage; // 用于显示背景地球图像 29 | 30 | public EarthquakeMapApp() { 31 | initialize(); 32 | loadEarthquakeData(); // 初始加载地震数据 33 | startDataRefresh(); // 开始定时更新地震数据 34 | } 35 | 36 | private void initialize() { 37 | // 主窗口设置 38 | frame = new JFrame("Earthquake Map"); 39 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 40 | frame.setSize(1200, 800); 41 | frame.setLayout(new BorderLayout()); 42 | 43 | // 左侧地震信息面板 44 | JPanel leftPanel = new JPanel(); 45 | leftPanel.setPreferredSize(new Dimension(300, 800)); 46 | leftPanel.setLayout(new BorderLayout()); 47 | 48 | earthquakeInfoArea = new JTextArea(); 49 | earthquakeInfoArea.setEditable(false); 50 | leftPanel.add(new JScrollPane(earthquakeInfoArea), BorderLayout.CENTER); 51 | 52 | frame.add(leftPanel, BorderLayout.WEST); 53 | 54 | // 右侧地图面板 55 | mapPanel = new MapPanel(); 56 | mapPanel.setBackground(Color.LIGHT_GRAY); 57 | waypoints = new ArrayList<>(); // 初始化为空 58 | 59 | // 加载地球图像背景 60 | try { 61 | earthImage = ImageIO.read(new File("F:\\edge_downloads\\earth_image.jpg")); // 这里你需要提供一个地球图像 62 | } catch (IOException e) { 63 | e.printStackTrace(); 64 | } 65 | 66 | // 为标记添加点击事件 67 | mapPanel.addMouseListener(new MouseAdapter() { 68 | @Override 69 | public void mouseClicked(MouseEvent e) { 70 | Point clickedPoint = e.getPoint(); 71 | for (EarthquakeWaypoint waypoint : waypoints) { 72 | Point2D point = geoToPixel(waypoint.getPosition()); 73 | if (point.distance(clickedPoint) < 10) { 74 | displayEarthquakeInfo(waypoint); 75 | } 76 | } 77 | } 78 | 79 | @Override 80 | public void mousePressed(MouseEvent e) { 81 | // 记录鼠标按下的位置,用于拖拽地图 82 | mapPanel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 83 | } 84 | 85 | @Override 86 | public void mouseReleased(MouseEvent e) { 87 | mapPanel.setCursor(Cursor.getDefaultCursor()); 88 | } 89 | }); 90 | 91 | mapPanel.addMouseMotionListener(new MouseAdapter() { 92 | @Override 93 | public void mouseDragged(MouseEvent e) { 94 | // 鼠标拖动时计算地图偏移 95 | int dx = e.getX() - mapPanel.getWidth() / 2; 96 | int dy = e.getY() - mapPanel.getHeight() / 2; 97 | 98 | mapCenterX -= dx / (100.0 * zoomLevel); // 经度的偏移量 99 | mapCenterY += dy / (100.0 * zoomLevel); // 纬度的偏移量 100 | 101 | mapPanel.repaint(); 102 | } 103 | }); 104 | 105 | // 添加鼠标滚轮缩放功能 106 | mapPanel.addMouseWheelListener(new MouseWheelListener() { 107 | @Override 108 | public void mouseWheelMoved(MouseWheelEvent e) { 109 | if (e.getWheelRotation() < 0) { 110 | zoomIn(); // 放大 111 | } else { 112 | zoomOut(); // 缩小 113 | } 114 | } 115 | }); 116 | 117 | frame.add(mapPanel, BorderLayout.CENTER); 118 | frame.setVisible(true); 119 | } 120 | 121 | // 放大地图 122 | private void zoomIn() { 123 | zoomLevel *= 1.1; // 放大10% 124 | mapPanel.repaint(); 125 | } 126 | 127 | // 缩小地图 128 | private void zoomOut() { 129 | zoomLevel /= 1.1; // 缩小10% 130 | mapPanel.repaint(); 131 | } 132 | 133 | // 将地理位置转换为像素位置 134 | private Point2D geoToPixel(GeoPosition position) { 135 | int x = (int) ((position.getLongitude() - mapCenterX + 180) * (mapPanel.getWidth() / 360.0) * zoomLevel); 136 | int y = (int) ((90 - position.getLatitude() - mapCenterY) * (mapPanel.getHeight() / 180.0) * zoomLevel); 137 | return new Point2D.Double(x, y); 138 | } 139 | 140 | // 显示地震详细信息 141 | private void displayEarthquakeInfo(EarthquakeWaypoint waypoint) { 142 | earthquakeInfoArea.setText("Location: " + waypoint.getLocationName() + "\n" + 143 | "Magnitude: " + waypoint.getMagnitude() + "\n" + 144 | "Depth: " + waypoint.getDepth() + " km\n" + 145 | "Time: " + waypoint.getTime()); 146 | } 147 | 148 | // 加载地震数据(从 API 获取真实数据) 149 | private void loadEarthquakeData() { 150 | waypoints.clear(); // 清空之前的数据 151 | try { 152 | String urlString = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson"; 153 | URL url = new URL(urlString); 154 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 155 | conn.setRequestMethod("GET"); 156 | 157 | BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 158 | String inputLine; 159 | StringBuilder content = new StringBuilder(); 160 | while ((inputLine = in.readLine()) != null) { 161 | content.append(inputLine); 162 | } 163 | in.close(); 164 | conn.disconnect(); 165 | 166 | // 解析 JSON 数据 167 | JsonElement jsonElement = JsonParser.parseString(content.toString()); 168 | JsonArray features = jsonElement.getAsJsonObject().getAsJsonArray("features"); 169 | 170 | for (JsonElement feature : features) { 171 | var properties = feature.getAsJsonObject().getAsJsonObject("properties"); 172 | 173 | // 确保字段存在且不为 null 174 | double magnitude = properties.has("mag") && !properties.get("mag").isJsonNull() ? properties.get("mag").getAsDouble() : 0.0; 175 | String location = properties.has("place") && !properties.get("place").isJsonNull() ? properties.get("place").getAsString() : "Unknown Location"; 176 | long time = properties.has("time") && !properties.get("time").isJsonNull() ? properties.get("time").getAsLong() : 0; 177 | double depth = properties.has("depth") && !properties.get("depth").isJsonNull() ? properties.get("depth").getAsDouble() : 0.0; 178 | 179 | JsonArray coordinates = feature.getAsJsonObject().getAsJsonObject("geometry").getAsJsonArray("coordinates"); 180 | // 获取坐标,检查是否存在 181 | double longitude = coordinates.size() > 1 ? coordinates.get(0).getAsDouble() : 0.0; 182 | double latitude = coordinates.size() > 0 ? coordinates.get(1).getAsDouble() : 0.0; 183 | 184 | GeoPosition position = new GeoPosition(latitude, longitude); 185 | waypoints.add(new EarthquakeWaypoint(position, location, magnitude, depth, new java.util.Date(time).toString())); 186 | } 187 | mapPanel.repaint(); // 更新地图 188 | } catch (Exception e) { 189 | e.printStackTrace(); 190 | } 191 | } 192 | 193 | // 定时更新地震数据 194 | private void startDataRefresh() { 195 | new Timer(60000, e -> loadEarthquakeData()).start(); // 每分钟更新一次 196 | } 197 | 198 | public static void main(String[] args) { 199 | SwingUtilities.invokeLater(EarthquakeMapApp::new); 200 | } 201 | 202 | // 自定义地图面板 203 | class MapPanel extends JPanel { 204 | @Override 205 | protected void paintComponent(Graphics g) { 206 | super.paintComponent(g); 207 | 208 | // 绘制背景地图(假设已经加载了地球图像) 209 | if (earthImage != null) { 210 | int imgWidth = earthImage.getWidth(null); 211 | int imgHeight = earthImage.getHeight(null); 212 | g.drawImage(earthImage, 0, 0, (int)(getWidth() * zoomLevel), (int)(getHeight() * zoomLevel), this); 213 | } 214 | 215 | // 绘制地震标记 216 | g.setColor(Color.RED); 217 | for (EarthquakeWaypoint waypoint : waypoints) { 218 | Point2D point = geoToPixel(waypoint.getPosition()); 219 | g.fillOval((int) point.getX() - 5, (int) point.getY() - 5, 10, 10); 220 | } 221 | } 222 | } 223 | 224 | // 自定义地震标记类 225 | class EarthquakeWaypoint { 226 | private GeoPosition position; 227 | private String locationName; 228 | private double magnitude; 229 | private double depth; 230 | private String time; 231 | 232 | public EarthquakeWaypoint(GeoPosition position, String locationName, double magnitude, double depth, String time) { 233 | this.position = position; 234 | this.locationName = locationName; 235 | this.magnitude = magnitude; 236 | this.depth = depth; 237 | this.time = time; 238 | } 239 | 240 | public GeoPosition getPosition() { 241 | return position; 242 | } 243 | 244 | public String getLocationName() { 245 | return locationName; 246 | } 247 | 248 | public double getMagnitude() { 249 | return magnitude; 250 | } 251 | 252 | public double getDepth() { 253 | return depth; 254 | } 255 | 256 | public String getTime() { 257 | return time; 258 | } 259 | } 260 | 261 | // 自定义地理坐标类 262 | class GeoPosition { 263 | private double latitude; 264 | private double longitude; 265 | 266 | public GeoPosition(double latitude, double longitude) { 267 | this.latitude = latitude; 268 | this.longitude = longitude; 269 | } 270 | 271 | public double getLatitude() { 272 | return latitude; 273 | } 274 | 275 | public double getLongitude() { 276 | return longitude; 277 | } 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 64 | 65 | 70 | 71 | 72 | 74 | 75 | 83 | 84 | 85 | 87 | { 88 | "customColor": "", 89 | "associatedIndex": 8 90 | } 91 | 92 | 93 | 94 | 95 | 96 | 99 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 139 | 140 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 1730724275754 166 | 182 | 183 | 184 | 185 | 187 | 188 | 189 | 190 | 191 | 192 | 194 | 195 | 196 | 198 | 199 | 200 | 201 | 202 | 203 |