我的問題是,單擊Browse按鈕后,它會顯示目錄中的所有文件供選擇,然后所選的圖像會正確顯示在GUI中。但是,當我第二次單擊“瀏覽”按鈕時,它僅顯示舊圖像,而不顯示新圖像。請幫助我。package GUI;import java.awt.BorderLayout;import java.awt.EventQueue;import java.awt.Graphics2D;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JLabel;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;@SuppressWarnings("serial")public class MainAppFrame extends JFrame { private JPanel contentPane; File targetFile; BufferedImage targetImg; public JPanel panel,panel_1; private static final int baseSize = 128; private static final String basePath =![enter image description here][1] "C:\\Documents and Settings\\Administrator\\Desktop\\Images"; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainAppFrame frame = new MainAppFrame(); frame.setVisible(true); frame.setResizable(false); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public MainAppFrame() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 550, 400); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0));
瀏覽圖像文件并使用Java Swing顯示它
幕布斯6054654
2019-11-04 10:05:12
