可能であれば、私を助けてもらえますか?Java を学ぼうとしながら、自分の小さな「映画」プロジェクトをやっています。
ボタンがクリックされたときにテキストを表示する JLabel を作成できました。これは基本的に私のお気に入りの映画に関するものです。そのため、Commando ボタンをクリックすると、その簡単な概要がポップアップ表示されます。そこで、Java パッケージと同じフォルダーにある画像を追加することにしました。
テキストと同時に表示されるように画像を適用する方法を調査しましたが、機能していないようです。まだまだ学ぶことがたくさんありますので、ご指導よろしくお願いします!!
助けてくれてありがとう!! ;]
ダズ。
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import java.awt.event.*;
import javax.swing.ImageIcon;
public class Movies {
JFrame frame;
JLabel label;
public static void main(String []args){
Movies gui = new Movies();
gui.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton commandoButton = new JButton("Commando");
commandoButton.addActionListener(new LabelListener());
frame.setLayout(null); // equivalent to frame.getContentPane().setLayout(null);
frame.add(commandoButton); // equivalent to frame.getContentPane().add(button);
commandoButton.setBounds(10, 10, 150, 25);
JButton predatorButton = new JButton("Predator");
predatorButton.addActionListener(new LabelListenerA());
frame.setLayout(null); // equivalent to frame.getContentPane().setLayout(null);
frame.add(predatorButton); // equivalent to frame.getContentPane().add(button);
predatorButton.setBounds(10, 40, 150, 25);
JButton expendablesButton = new JButton("The Expendables");
expendablesButton.addActionListener(new LabelListenerB());
frame.setLayout(null); // equivalent to frame.getContentPane().setLayout(null);
frame.add(expendablesButton); // equivalent to frame.getContentPane().add(button);
expendablesButton.setBounds(10, 70, 150, 25);
frame.getContentPane().add(BorderLayout.WEST, commandoButton);
frame.setSize(1000, 350);
frame.setVisible(true);
}
JTextPane labelCommando = new JTextPane();
class LabelListener implements ActionListener {
public void actionPerformed(ActionEvent commandoButton){
labelCommando.setText("A retired elite Black Ops Commando launches a one man war against a group of South American criminals who have kidnapped his daughter to blackmail him into starting a revolution and getting an exiled dictator back into power. ");
frame.add(labelCommando);
labelCommando.setBounds(170, 10, 500, 200);
labelCommando.setOpaque(false);
String imgStr = "images/commando.jpg";
ImageIcon image = new ImageIcon("commando.jpg");
JLabel labelCommando = new JLabel(" ", image, JLabel.CENTER);
label.setIcon(image);
}
} // Close inner class
class LabelListenerA implements ActionListener {
public void actionPerformed(ActionEvent predatorButton){
labelCommando.setText("Not long after they land, Dutch and his team discover that they have been sent under false pretenses. This deception turns out to be the least of their worries though, when they find themselves being methodically hunted by something not of this world...");
frame.add(labelCommando);
labelCommando.setBounds(170, 10, 500, 200);
labelCommando.setOpaque(false);
}
} // Close inner class
class LabelListenerB implements ActionListener {
public void actionPerformed(ActionEvent expendablesButton){
labelCommando.setText("Barney Ross leads the 'Expendables', a band of highly skilled mercenaries including knife enthusiast Lee Christmas, martial arts expert Yin Yang, heavy weapons specialist Hale Caesar, demolitionist Toll Road and loose-cannon sniper Gunner Jensen. When the group is commissioned by the mysterious Mr. Church to assassinate the merciless dictator of a small South American island, Barney and Lee head to the remote locale to scout out their opposition. Once there, they meet with local rebel Sandra and discover the true nature of the conflict engulfing the city. When they escape the island and Sandra stays behind, Ross must choose to either walk away and save his own life - or attempt a suicidle rescue mission that might just save his soul.");
frame.add(labelCommando);
labelCommando.setBounds(170, 10, 500, 200);
labelCommando.setOpaque(false);
}
} // Close inner class
}