基本上,我從BufferedImages中實時提取視頻圖像,並在處理後在JFrame中顯示它們。不幸的是,我對swing的處理非常糟糕,所以當圖像按照預期顯示在JFrame中時,它會爲每個新圖像產生一個新的JFrame(每秒24個)。訪問BufferedImages以更新JFrame組件
我送BufferedImages到GUI用:
UserInterface.main(currentFrame);
,他們是由我的GUI類,它本質上是一個包含一個JFrame裏面一個JPanel裏面的當前圖像的JLabel接受:
public class UserInterface extends JFrame {
private JPanel contentPane;
public static void main(BufferedImage inputImage) throws IOException
{
UserInterface frame = new UserInterface(inputImage);
frame.setVisible(true);
}
public UserInterface(BufferedImage inputImage) throws IOException
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(50, 50, 1024, 768);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel imageLabel = new JLabel(new ImageIcon(inputImage));
add(imageLabel);
imageLabel.setBounds(11, 60, 480, 360);
contentPane.add(imageLabel);
}
任何人都可以建議如何打破這一點,使1只JFrame出現,其中我可以動態顯示所有圖像?
'contentPane.setLayout(null);'Java GUI必須在不同的操作系統上工作',屏幕大小,屏幕分辨率等。因此,它們不利於像素的完美佈局。請使用佈局管理器或[它們的組合](http://stackoverflow.com/a/5630271/418556)以及[white space]的佈局填充和邊框(http://stackoverflow.com/a/17874718/ 418556)。 – 2014-12-07 03:36:06