擺動轉換圖像我有2類定義是這樣的:一個按鈕
public class Cartes extends JPanel
{
private BufferedImage image;
protected int tabC[] = new int[9];
public int randomC ;
public Cartes()
{
..........
BufferedImage myPicture = null;
try {
myPicture = ImageIO.read(new File("images/"+randomC+".png"));
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
add(picLabel);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(image, 0, 0, null); //
}
}
注:randomC
是在構造函數中讓我在隨機圖像選擇生成一個整數。
和
public class VueGeo extends JFrame
{
public Cartes pan = new Cartes();
private JButton bouton = new JButton("Change");
public VueGeo()
{
...
container.add(pan, BorderLayout.CENTER);
bouton.addActionListener(new BoutonListener());
...
this.setContentPane(container);
this.setVisible(true);
}
class BoutonListener implements ActionListener
{
public void actionPerformed(ActionEvent arg0) {
????????
}
}
}
的問題是我不知道要放什麼actionPerformed
爲了讓我改變形象每當我上的更改單擊。有人有想法嗎?
1)請使用一致的和邏輯的縮進代碼塊。 2)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 –