From f34d0bc52b8a59df4541f90ca9e607df89dacac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=94=A6=E9=B8=BF?= <16780970+l-jhhh@user.noreply.gitee.com> Date: Tue, 16 Jun 2026 09:08:00 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20PR3Test/?= =?UTF-8?q?MainFrame.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PR3Test/MainFrame.java | 92 ------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 PR3Test/MainFrame.java diff --git a/PR3Test/MainFrame.java b/PR3Test/MainFrame.java deleted file mode 100644 index eddb4e3..0000000 --- a/PR3Test/MainFrame.java +++ /dev/null @@ -1,92 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; - -public class MainFrame extends JFrame { - - private JTextArea logArea; // - private JLabel imageLabel; // - - public MainFrame() { - // - setTitle("Issue #3 GUI 作业"); - setSize(800, 500); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLayout(new BorderLayout()); - - // --------------------------------------------------------- - // - // --------------------------------------------------------- - JPanel westPanel = new JPanel(); - westPanel.setLayout(new GridLayout(7, 6)); // 7行6列 = 42个格子 - - // - for (int i = 1; i <= 42; i++) { - String dateStr = "2026-06-" + String.format("%02d", i); // 生成 06-01 到 06-42 (演示用) - JButton dayBtn = new JButton(dateStr); - - // - dayBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - // - logArea.setText("当前选中的是:" + dayBtn.getText()); - } - }); - westPanel.add(dayBtn); - } - add(westPanel, BorderLayout.WEST); - - // --------------------------------------------------------- - // - // --------------------------------------------------------- - logArea = new JTextArea(); - logArea.setEditable(false); - logArea.setBorder(BorderFactory.createTitledBorder("日志显示区")); - add(logArea, BorderLayout.EAST); - - // --------------------------------------------------------- - // - // --------------------------------------------------------- - imageLabel = new JLabel("请点击下方按钮选择图片", JLabel.CENTER); - imageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); - add(imageLabel, BorderLayout.CENTER); - - // --------------------------------------------------------- - // - // --------------------------------------------------------- - JButton selectBtn = new JButton("选择图片并显示"); - selectBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - JFileChooser fileChooser = new JFileChooser(); - int result = fileChooser.showOpenDialog(MainFrame.this); - - if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fileChooser.getSelectedFile(); - - ImageIcon imageIcon = new ImageIcon(selectedFile.getAbsolutePath()); - - - Image img = imageIcon.getImage(); - Image newImg = img.getScaledInstance(400, 300, Image.SCALE_SMOOTH); - imageLabel.setIcon(new ImageIcon(newImg)); - imageLabel.setText(""); - } - } - }); - add(selectBtn, BorderLayout.SOUTH); - - - setLocationRelativeTo(null); - } - - public static void main(String[] args) { - SwingUtilities.invokeLater(() -> { - new MainFrame().setVisible(true); - }); - } -} \ No newline at end of file -- Gitee